Beispiel #1
0
        private void StickInTarget(Collision collision, bool bSkipRayCast)
        {
            Vector3 direction = this.prevRotation * Vector3.forward;

            if (!bSkipRayCast)
            {
                RaycastHit[] array = Physics.RaycastAll(this.prevHeadPosition - this.prevVelocity * Time.deltaTime, direction, this.prevVelocity.magnitude * Time.deltaTime * 2f);
                bool         flag  = false;
                foreach (RaycastHit raycastHit in array)
                {
                    if (raycastHit.collider == collision.collider)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    return;
                }
            }
            UnityEngine.Object.Destroy(this.glintParticle);
            this.inFlight                = false;
            this.shaftRB.velocity        = Vector3.zero;
            this.shaftRB.angularVelocity = Vector3.zero;
            this.shaftRB.isKinematic     = true;
            this.shaftRB.useGravity      = false;
            this.shaftRB.transform.GetComponent <BoxCollider>().enabled = false;
            this.arrowHeadRB.velocity        = Vector3.zero;
            this.arrowHeadRB.angularVelocity = Vector3.zero;
            this.arrowHeadRB.isKinematic     = true;
            this.arrowHeadRB.useGravity      = false;
            this.arrowHeadRB.transform.GetComponent <BoxCollider>().enabled = false;
            this.hitTargetSound.Play();
            this.scaleParentObject = new GameObject("Arrow Scale Parent");
            Transform       transform = collision.collider.transform;
            ExplosionWobble component = collision.collider.gameObject.GetComponent <ExplosionWobble>();

            if (!component && transform.parent)
            {
                transform = transform.parent;
            }
            this.scaleParentObject.transform.parent = transform;
            base.transform.parent   = this.scaleParentObject.transform;
            base.transform.rotation = this.prevRotation;
            base.transform.position = this.prevPosition;
            base.transform.position = collision.contacts[0].point - base.transform.forward * (0.75f - (Util.RemapNumberClamped(this.prevVelocity.magnitude, 0f, 10f, 0f, 0.1f) + UnityEngine.Random.Range(0f, 0.05f)));
        }
Beispiel #2
0
        //-------------------------------------------------
        private void StickInTarget(Collision collision, bool bSkipRayCast)
        {
            Vector3 prevForward = prevRotation * Vector3.forward;

            // Only stick in target if the collider is front of the arrow head
            if (!bSkipRayCast)
            {
                RaycastHit[] hitInfo;
                hitInfo = Physics.RaycastAll(prevHeadPosition - prevVelocity * Time.deltaTime, prevForward, prevVelocity.magnitude * Time.deltaTime * 2.0f);
                bool properHit = false;
                for (int i = 0; i < hitInfo.Length; ++i)
                {
                    RaycastHit hit = hitInfo[i];

                    if (hit.collider == collision.collider)
                    {
                        properHit = true;
                        break;
                    }
                }

                if (!properHit)
                {
                    return;
                }
            }

            Destroy(glintParticle);

            inFlight = false;

            SetCollisionMode(CollisionDetectionMode.Discrete, true);

            shaftRB.velocity        = Vector3.zero;
            shaftRB.angularVelocity = Vector3.zero;
            shaftRB.isKinematic     = true;
            shaftRB.useGravity      = false;
            shaftRB.transform.GetComponent <BoxCollider>().enabled = false;

            arrowHeadRB.velocity        = Vector3.zero;
            arrowHeadRB.angularVelocity = Vector3.zero;
            arrowHeadRB.isKinematic     = true;
            arrowHeadRB.useGravity      = false;
            arrowHeadRB.transform.GetComponent <BoxCollider>().enabled = false;

            hitTargetSound.Play();


            // If the hit item has a parent, dock an empty object to that
            // this fixes an issue with scaling hierarchy. I suspect this is not sustainable for a large object / scaling hierarchy.
            scaleParentObject = new GameObject("Arrow Scale Parent");
            Transform parentTransform = collision.collider.transform;

            // Don't do this for weebles because of how it has a fixed joint
            ExplosionWobble wobble = collision.collider.gameObject.GetComponent <ExplosionWobble>();

            if (!wobble)
            {
                if (parentTransform.parent)
                {
                    parentTransform = parentTransform.parent;
                }
            }

            scaleParentObject.transform.parent = parentTransform;

            // Move the arrow to the place on the target collider we were expecting to hit prior to the impact itself knocking it around
            transform.parent   = scaleParentObject.transform;
            transform.rotation = prevRotation;
            transform.position = prevPosition;
            transform.position = collision.contacts[0].point - transform.forward * (0.75f - (Util.RemapNumberClamped(prevVelocity.magnitude, 0f, 10f, 0.0f, 0.1f) + Random.Range(0.0f, 0.05f)));
        }