示例#1
0
        private void Update()
        {
            velocity += Gravity * fixedDeltaTime * (UseGravity ? 1 : 0);

            if (!IsKinematic)
            {
                velocity *= (1 - (Drag * fixedDeltaTime));
            }

            velocity = (Vector3.Right * velocity.X * (X ? 0 : 1)) + (Vector3.Up * velocity.Y * (Y ? 0 : 1)) + (Vector3.Forward * velocity.Z * (Z ? 0 : 1));

            if (CheckCollision(Vector3.Up * velocity.Y * deltaTime) != null)
            {
                if (collider.GetPhysicsMaterial() != null)
                {
                    velocity = collider.GetPhysicsMaterial().CalculateFriction(velocity, Vector3.Zero, Vector3.Magnitude(Gravity) * Mass, Mass);
                }

                if (CheckCollision(Vector3.Up * velocity.Y * deltaTime).GetCenter().Y + CheckCollision(Vector3.Up * velocity.Y * deltaTime).GetSize().Y <= collider.GetCenter().Y)
                {
                    velocity.Y = 0;
                }
            }

            position += velocity * deltaTime;
            pos       = position.ToUnity();
            this.transform.position = pos;
        }
 public static Vector3 ToPhysics(this UnityEngine.Vector3 value) => new Vector3(value.x, value.y, value.z);