示例#1
0
        public void Move(Vector3 move, bool crouch, bool jump)
        {
            // convert the world relative moveInput vector into a local-relative
            // turn amount and forward amount required to head in the desired
            // direction.
            if (move.magnitude > 1f)
            {
                move.Normalize();
            }
            move = transform.InverseTransformDirection(move);
            CheckGroundStatus();
            move            = Vector3.ProjectOnPlane(move, m_GroundNormal);
            m_TurnAmount    = Mathf.Atan2(move.x, move.z);
            m_ForwardAmount = move.z;

            if (_hanging)
            {
                if (m_Animator.GetCurrentAnimatorStateInfo(0).fullPathHash == _hashStateHangIdle)
                {
                    if (jump)                      //drop from hanging
                    {
                        _hangHandler.HangToDrop();
                    }
                    else if (m_ForwardAmount > 0)                        //climb from hanging
                    {
                        _hangHandler.HangToClimb();
                    }
                }
            }
            else                //turn when not hanging
            {
                ApplyExtraTurnRotation();
            }

            // control and velocity handling is different when grounded and airborne:
            if (m_IsGrounded)
            {
                HandleGroundedMovement(crouch, jump);
            }
            else if (!_hanging)
            {
                HandleAirborneMovement();
            }

            ScaleCapsuleForCrouching(crouch);
            PreventStandingInLowHeadroom();

            // send input and other state parameters to the animator
            UpdateAnimator(move);
        }
示例#2
0
    public void Move(float v, float h, bool crouch, bool jump, bool checkGrounded = true)
    {
        if (checkGrounded)
        {
            CheckGroundStatus();
        }

        // control and velocity handling is different when grounded and airborne:
        if (!IsGrounded)
        {
            HandleAirborneMovement(v, h);
        }
        else
        {
            HandleGroundedMovement(v, h, crouch, jump);
        }
        ScaleCapsuleForCrouching(crouch);

        //don't move when handing
        if (Hanging && _hangHandler)
        {
            if (_animator.GetCurrentAnimatorStateInfo(0).fullPathHash == _hashStateHangIdle)
            {
//				print ("State check passed");
                if (jump)                  //drop from hanging
                {
                    _hangHandler.HangToDrop();
//					print ("dropping");
                }
                else if (v > 0)                    //climb from hanging
                {
                    _hangHandler.HangToClimb();
//					print ("climbing");
                }
            }
            else
            {
//				print ("State check failed");
            }
        }
        else
        {
//			print (Hanging.ToString () + ", " + _hangHandler.ToString ());

            //slow or stop air movement
            if (!IsGrounded)
            {
                //adjust velocity to move around while in air
                //todo : clamp & moveposition
//				Debug.Log ("Not grounded");
            }
            else
            {
//				Debug.Log ("moving, amount : " + (_rigidbody.position + _hsc.GetPreferredSpeed (transform.forward) * transform.forward * v * Time.fixedDeltaTime).magnitude.ToString ());
                //move rigidbody
                transform.position += _hsc.GetPreferredSpeed(transform.forward) * transform.forward * v * Time.fixedDeltaTime;
                transform.position += _hsc.GetPreferredSpeed(transform.right) * transform.right * h * Time.fixedDeltaTime;
//				_rigidbody.MovePosition (_rigidbody.position + _hsc.GetPreferredSpeed (transform.forward) * transform.forward * v * Time.fixedDeltaTime);
//				_rigidbody.MovePosition (_rigidbody.position + _hsc.GetPreferredSpeed (transform.right) * transform.right * h * Time.fixedDeltaTime);
            }
//			_rigidbody.transform.Translate (_hsc.GetPreferredSpeed (transform.forward) * Vector3.forward * v * Time.fixedDeltaTime);
//			_rigidbody.transform.Translate (_hsc.GetPreferredSpeed (transform.right) * Vector3.right * h * Time.fixedDeltaTime);
        }
    }