- Home /
 
Applying accleration to character controller without pressing keys
Hey, I'm making a game in which the player must navigate a capsule along platforms and avoid obstacles etc. Most of my code is in C# but I'm using the ThirdPersonController and ThirdPersonCamera which are Javascript. Anyway I want the player to continuously accelerate forward until a max speed is reached, even when they are not pressing any keys.
I'm a bit of a Javascript noob and only usually use c# with Unity. I think the problem is that two different scripts are trying to alter the velocity of the player. Here is the code in my PlayerController script (separate from the ThirdPersonController):
         CharacterController controller = GetComponent<CharacterController>();
      
         Vector3 horizontalVelocity = new Vector3(0f, 0f, controller.velocity.z);
         float horizontalSpeed = horizontalVelocity.magnitude;
         
         //FOV EFFECT////////////////////////////////////
         currentFOV = Camera.main.fieldOfView;
         targetFOV = (horizontalVelocity.z*FOVFactor)+30;
         ////////////////////////////////////////////////
         
         Camera.main.fieldOfView = Mathf.Lerp (currentFOV, targetFOV, 0.1f);
         
         /*if (controller.isGrounded) {
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
               
         }*/
         
         newSpeed = speedMultiplier+lastSpeed;
         controller.Move((newSpeed)*Time.deltaTime);
         lastSpeed = horizontalVelocity;
         
         
 
              Your answer
 
             Follow this Question
Related Questions
unity game 1 Answer
Network view not attached 0 Answers
Third-Person Camera keeps intersecting with terrain/buildings 2 Answers
multi game network 0 Answers
Dose any one know how to send object current postion to preivues posistion 1 Answer