Ejemplo 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();
        }
Ejemplo n.º 2
0
        private void LateUpdate()
        {
            gravityAlignment = Quaternion.FromToRotation(
                gravityAlignment * Vector3.up, CustomGravity.GetUpAxis(focusPoint)) * gravityAlignment;

            UpdateFocusPoint();
            ManualRotation();

            if (ManualRotation() || AutomaticRotation())
            {
                ConstrainAngles();
                orbitRotation = Quaternion.Euler(orbitAngles);
            }

            Quaternion lookRotation = gravityAlignment * orbitRotation;

            Vector3 lookDirection = lookRotation * Vector3.forward;
            Vector3 lookPosition  = focusPoint - lookDirection * distance;


            Vector3 rectOffset    = lookDirection * regularCamera.nearClipPlane;
            Vector3 rectPosition  = lookPosition + rectOffset;
            Vector3 castFrom      = focus.position;
            Vector3 castLine      = rectPosition - castFrom;
            float   castDistance  = castLine.magnitude;
            Vector3 castDirection = castLine / castDistance;

            if (Physics.BoxCast(
                    castFrom, CameraHalfExtends, castDirection, out RaycastHit hit,
                    lookRotation, castDistance, obstructionMask))
            {
                rectPosition = castFrom + castDirection * hit.distance;
                lookPosition = rectPosition - rectOffset;
            }

            transform.SetPositionAndRotation(lookPosition, lookRotation);
        }