void Start()
        {
            controller   = GetComponent <CharacterController>();
            powerup      = GetComponent <PlayerPowerupBehavior>();
            inputManager = FindObjectOfType <InputManager>();
            lm           = FindObjectOfType <LevelManager>();
            buzzSfx      = GetComponent <AudioSource>();
            buzzSfx.Play();

            Cursor.visible   = false;
            Cursor.lockState = CursorLockMode.Locked;

            currState = PlayerFlightState.Flying;
        }
        private void FlyingControl(Vector2 input)
        {
            if (inputManager.GetSpeedUpBtnClicked())
            {
                currSpeed    += speedIncr;
                currRotSpeed += rotSpeedIncr;
            }

            if (inputManager.GetSlowDownBtnClicked())
            {
                currSpeed    -= speedIncr;
                currRotSpeed -= rotSpeedIncr;
            }
            currSpeed = Mathf.Clamp(currSpeed, minSpeed, maxSpeed + PlayerUpgrades.maxSpeedAdd);

            float boostedSpeed = currSpeed;

            if (PlayerPowerupBehavior.GetActiveCurrentPowerup() == PlayerPowerup.Vortex)
            {
                boostedSpeed += PlayerPowerupBehavior.vortexSpeedBoost;
            }
            move = transform.forward * boostedSpeed;

            currRotSpeed.x = Mathf.Clamp(currRotSpeed.x, minRotSpeed.x, maxRotSpeed.x);
            currRotSpeed.y = Mathf.Clamp(currRotSpeed.y, minRotSpeed.y, maxRotSpeed.y);

            Vector3 yaw   = transform.right * (input.x * currRotSpeed.x * Time.deltaTime);
            Vector3 pitch = transform.up * (input.y * currRotSpeed.y * Time.deltaTime);
            Vector3 dir   = yaw + pitch;

            if (Math.Abs(dir.magnitude) > Mathf.Epsilon)
            {
                // limit x rotation to avoid going getting stuck in a loop
                float maxX         = Quaternion.LookRotation(move + dir).eulerAngles.x;
                bool  enteringLoop = (maxX < 90 && maxX > 70 || maxX > 270 && maxX < 290);

                if (!enteringLoop)
                {
                    move += dir;
                    transform.rotation = Quaternion.LookRotation(move);
                }
            }


            controller.Move((move + controllerOffset) * Time.deltaTime);
        }
Beispiel #3
0
        public void Follow()
        {
            Vector3 _offset = flyingOffset;

            switch (player.currState)
            {
            case PlayerFlightState.Flying:
                _offset = flyingOffset;
                break;

            case PlayerFlightState.Landed:
                _offset = landedOffset;
                break;
            }

            // is this too hard to control? probably idk... no i think its too hard.... no its fine.... idk anymore
            float targetSpeed = (PlayerPowerupBehavior.GetActiveCurrentPowerup() == PlayerPowerup.Vortex)
                ? (speed + PlayerPowerupBehavior.vortexSpeedBoost) : speed;

            currSpeed = Mathf.Lerp(currSpeed, targetSpeed, Time.deltaTime);

            desiredPos         = lookAtTransform.position;
            desiredPos        += lookAtTransform.right * _offset.x;
            desiredPos        += lookAtTransform.up * _offset.y;
            desiredPos        += lookAtTransform.forward * _offset.z;
            transform.position = Vector3.Lerp(transform.position, desiredPos, currSpeed * Time.deltaTime);

            Vector3 desiredLook = lookAtTransform.forward + forwardEulerOffest;

            transform.forward = Vector3.Lerp(transform.forward, desiredLook, currSpeed * Time.deltaTime);

            if (player.currState == PlayerFlightState.Flying)
            {
                cameraLag = desiredPos - transform.position;
            }
        }