/**
         * Updates the camera's transform.
         * This is called every frame by StateHandler.
         */
        public void _UpdateFPCamera()
        {
            if (KickStarter.stateHandler.gameState != GameState.Normal)
            {
                return;
            }

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

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

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

                    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);
                }
                else if (headBobMethod == FirstPersonHeadBobMethod.CustomAnimation)
                {
                    if (headBobAnimator != null && headBobSpeedParameter != "")
                    {
                        headBobAnimator.SetFloat(headBobSpeedParameter, GetHeadBobSpeed());
                    }
                }
            }

            if (allowMouseWheelZooming && _camera != null && KickStarter.stateHandler.gameState == AC.GameState.Normal)
            {
                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);
                }
            }
        }
Exemplo n.º 2
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()
        {
            Vector2 moveKeys = KickStarter.playerInput.GetMoveKeys();

            if ((moveKeys.x == 0f && moveKeys.y == 0f) || KickStarter.settingsManager.IsFirstPersonDragRotation() || (KickStarter.settingsManager.IsFirstPersonDragComplex() && Input.touchCount == 1) || !KickStarter.player.IsGrounded())
            {
                return(0f);
            }

            if (player != null)
            {
                return(player.GetMoveSpeed());
            }
            return(0f);
        }
Exemplo n.º 3
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);
                }
            }
        }