Exemplo n.º 1
0
        private void FixedUpdate()
        {
            Vector3 gravity = CustomGravity.GetGravity(body.position, out upAxis);

            UpdateState();
            AdjustVelocity();

            if (desiredJump)
            {
                desiredJump = false;
                Jump(gravity);
            }

            velocity     += gravity * Time.deltaTime;
            body.velocity = velocity;

            ClearState();
        }
        private void UpdateGravityAlignment()
        {
            Vector3 fromUp = gravityAlignment * Vector3.up;
            Vector3 toUp   = CustomGravity.GetUpAxis(focusPoint);

            float dot      = Mathf.Clamp(Vector3.Dot(fromUp, toUp), -1f, 1f);
            float angle    = Mathf.Acos(dot) * Mathf.Rad2Deg;
            float maxAngle = upAlignmentSpeed * Time.deltaTime;

            Quaternion newAlignment = Quaternion.FromToRotation(fromUp, toUp) * gravityAlignment;

            if (angle <= maxAngle)
            {
                gravityAlignment = newAlignment;
            }
            else
            {
                gravityAlignment = Quaternion.SlerpUnclamped(
                    gravityAlignment, newAlignment, maxAngle / angle
                    );
            }
        }
Exemplo n.º 3
0
 void OnDisable()
 {
     CustomGravity.Unregister(this);
 }
Exemplo n.º 4
0
 void OnEnable()
 {
     CustomGravity.Register(this);
 }