Beispiel #1
0
        private void Respawn(Vector3 position, Quaternion rotation)
        {
            puppet.puppetMaster.state = PuppetMaster.State.Alive;
            puppet.puppetMaster.targetAnimator.Play(idleAnimation, 0, 0f);
            puppet.SetState(BehaviourPuppet.State.Puppet);
            puppet.puppetMaster.Teleport(position, rotation, true);

            puppetRoot.parent = null;
        }
Beispiel #2
0
    //  Falling Management
    //  If Character has puppetmaster then use puppetbehavious, otherwise play animation
    private bool FallingManagement()
    {
        bool       _fall = false;
        RaycastHit downwardHit;

        if (Physics.Raycast(transform.position, Vector3.down, out downwardHit, 100f, layerMaskHeightAdjust))
        {
            float disBetweenCharAndFloor = downwardHit.distance - 50f;       //  50f is the fixed distance from Floor layer to HeightAdjust layer.
            if (disBetweenCharAndFloor > 5f || disBetweenCharAndFloor <= -5) //  if player get up heigher 5 or lower 5 than floor
            {
                _fall = true;
            }
        }
        else    //  ray is not hitting HeightAdjust layer at all
        {
            _fall = true;
        }

        if (_fall)
        {
            if (BehaviourPuppet != null)
            {
                BehaviourPuppet.SetState(BehaviourPuppet.State.Unpinned);
            }
            else
            {
                if (!isFalling)
                {
                    isFalling = true;
                    return(true);
                }
            }
        }
        else
        {
            if (isFalling)
            {
                isFalling = false;
            }
        }

        return(false);
    }
Beispiel #3
0
        void OnCollisionEnter(Collision collision)
        {
            if (grabbed)
            {
                return;                      // If we have not grabbed anything yet...
            }
            if (Time.time < nextGrabTime)
            {
                return;                                       // ...and enough time has passed since the last release...
            }
            if (collision.gameObject.layer != grabLayer)
            {
                return;                                                      // ...and the collider is on the right layer...
            }
            if (collision.rigidbody == null)
            {
                return;                                          // ...and it has a rigidbody attached.
            }
            // Find MuscleCollisionBroadcaster that is a component added to all muscles by the PM, it broadcasts collisions events to PM and its behaviours.
            var m = collision.gameObject.GetComponent <MuscleCollisionBroadcaster>();

            if (m == null)
            {
                return;                        // Make sure the collider we collided with is a muscle of a Puppet...
            }
            if (m.puppetMaster == puppetMaster)
            {
                return;                                             // ...and it is not the same puppet as ours.
            }
            // Unpin the puppet we collided with
            foreach (BehaviourBase b in m.puppetMaster.behaviours)
            {
                if (b is BehaviourPuppet)
                {
                    otherPuppet = b as BehaviourPuppet;
                    otherPuppet.SetState(BehaviourPuppet.State.Unpinned); // Unpin
                    otherPuppet.canGetUp = false;                         // Make it not get up while being held
                }
            }

            if (otherPuppet == null)
            {
                return;                                  // If not BehaviourPuppet found, break out
            }
            // Adding a ConfigurableJoint to link the two puppets
            joint = gameObject.AddComponent <ConfigurableJoint>();
            joint.connectedBody = collision.rigidbody;

            // Move the anchor to where the hand is (since we done have a rigidbody for the hand)
            joint.anchor = new Vector3(-0.35f, 0f, 0f);

            // Lock linear and angular motion of the joint
            joint.xMotion        = ConfigurableJointMotion.Locked;
            joint.yMotion        = ConfigurableJointMotion.Locked;
            joint.zMotion        = ConfigurableJointMotion.Locked;
            joint.angularXMotion = ConfigurableJointMotion.Locked;
            joint.angularYMotion = ConfigurableJointMotion.Locked;
            joint.angularZMotion = ConfigurableJointMotion.Locked;

            // Increasing the mass of the linked Rigidbody when it is a part of a chain is the easiest way to improve link stability.
            r.mass *= massMlp;

            // Solver iteration count needs to be increased to improve stability of the link between 2 long joint chains.
            puppetMaster.solverIterationCount *= solverIterationMlp;

            // Ignore collisions with the object we grabbed
            otherCollider = collision.collider;
            Physics.IgnoreCollision(c, otherCollider, true);

            // The other puppet is heavy so slow down..
            userControl.walkByDefault = true;

            // We have successfully grabbed the other puppet
            grabbed = true;
        }