コード例 #1
0
        public void ClampSpeed()
        {
            float speedFactor = flyingSpeed / GetComponent <Rigidbody>().velocity.magnitude;

            if (speedFactor < 1)
            {
                Vector3 flatVelocity = VectorUtilities.GetFlatVector3(GetComponent <Rigidbody>().velocity);
                GetComponent <Rigidbody>().velocity = new Vector3(flatVelocity.x * speedFactor, GetComponent <Rigidbody>().velocity.y, flatVelocity.z * speedFactor);
            }
        }
コード例 #2
0
        private void RotatePlayerVelocityAlongTangent()
        {
            Vector3 currentVelocity     = GetComponent <Rigidbody>().velocity;
            Vector3 currentFlatVelocity = VectorUtilities.GetFlatVector3(currentVelocity);
            Vector3 currentFlatTangent  = VectorUtilities.PositionToTangentVector(transform.position, EnvironmentController.Instance.levelCenter.position);

            float velocityOffsetAngle = Vector2.Angle(new Vector2(currentFlatTangent.x, currentFlatTangent.z), new Vector2(currentVelocity.x, currentVelocity.z));

            float flatVelocity = 0;

            if (velocityOffsetAngle <= 90)
            {
                flatVelocity = currentFlatVelocity.magnitude;
            }
            else
            {
                flatVelocity = -1 * currentFlatVelocity.magnitude;
            }
            GetComponent <Rigidbody>().velocity = new Vector3(currentFlatTangent.x * flatVelocity, currentVelocity.y, currentFlatTangent.z * flatVelocity);
            velocity = GetComponent <Rigidbody>().velocity;
        }
コード例 #3
0
        public float GetPlayerHorizontalSpeed()
        {
            Vector3 flatVelocity = VectorUtilities.GetFlatVector3(GetComponent <Rigidbody>().velocity);

            return(flatVelocity.magnitude);
        }