Beispiel #1
0
 /**
  * <summary>Gets the desired head-bobbing speed, to be manipulated via a custom script if headBobMethod = FirstPersonHeadBobMethod.CustomScript.</summary>
  * <returns>The desired head-bobbing speed. Returns zero if the player is idle.</returns>
  */
 public float GetHeadBobSpeed()
 {
     if (player != null && player.IsGrounded(true))
     {
         return(Mathf.Abs(player.GetMoveSpeed()));
     }
     return(0f);
 }
Beispiel #2
0
        /**
         * Updates the camera's transform.
         * This is called every frame by StateHandler.
         */
        public void _UpdateFPCamera()
        {
            if (actualTilt != targetTilt)
            {
                if (player)
                {
                    actualTilt = tiltLerp.Update(actualTilt, targetTilt, player.turnSpeed);
                }
                else
                {
                    actualTilt = tiltLerp.Update(actualTilt, targetTilt, 7f);
                }
            }

            ApplyTilt();

            if (headBob)
            {
                switch (headBobMethod)
                {
                case FirstPersonHeadBobMethod.BuiltIn:
                {
                    deltaHeight = 0f;

                    float bobSpeed  = GetHeadBobSpeed();
                    float waveSlice = Mathf.Sin(bobTimer);

                    bobTimer += Mathf.Abs(player.GetMoveSpeed()) * Time.deltaTime * 5f * builtInSpeedFactor;

                    if (bobTimer > Mathf.PI * 2)
                    {
                        bobTimer = bobTimer - (2f * Mathf.PI);
                    }

                    float totalAxes = Mathf.Clamp(bobSpeed, 0f, 1f);

                    deltaHeight = totalAxes * waveSlice * bobbingAmount;

                    transform.localPosition = new Vector3(transform.localPosition.x, height + deltaHeight, transform.localPosition.z);
                }
                break;

                case FirstPersonHeadBobMethod.CustomAnimation:
                    if (headBobAnimator)
                    {
                        bool isGrounded = (player && player.IsGrounded(true));

                        if (!string.IsNullOrEmpty(headBobSpeedParameter))
                        {
                            if (isGrounded)
                            {
                                float forwardDot = Vector3.Dot(player.TransformForward, player.GetMoveDirection());
                                headBobAnimator.SetFloat(headBobSpeedParameter, player.GetMoveSpeed() * forwardDot);
                            }
                            else
                            {
                                headBobAnimator.SetFloat(headBobSpeedParameter, 0f);
                            }

                            //	headBobAnimator.SetFloat (headBobSpeedParameter, GetHeadBobSpeed ());
                        }
                        if (!string.IsNullOrEmpty(headBobSpeedSideParameter))
                        {
                            if (isGrounded)
                            {
                                float rightDot = Vector3.Dot(player.TransformRight, player.GetMoveDirection());
                                headBobAnimator.SetFloat(headBobSpeedSideParameter, player.GetMoveSpeed() * rightDot);
                            }
                            else
                            {
                                headBobAnimator.SetFloat(headBobSpeedSideParameter, 0f);
                            }
                            //headBobAnimator.SetFloat (headBobSpeedSideParameter, GetHeadBobSpeed (true));
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            if (KickStarter.stateHandler.gameState != GameState.Normal)
            {
                return;
            }

            if (allowMouseWheelZooming && Camera)
            {
                float scrollWheelInput = KickStarter.playerInput.InputGetAxis("Mouse ScrollWheel");
                if (scrollWheelInput > 0f)
                {
                    Camera.fieldOfView = Mathf.Max(Camera.fieldOfView - 3, minimumZoom);
                }
                else if (scrollWheelInput < 0f)
                {
                    Camera.fieldOfView = Mathf.Min(Camera.fieldOfView + 3, maximumZoom);
                }
            }
        }