- Home /
Apply acceleration and Decceleration to transform.forward?
Hello, I had been following the youtuber gamesplusjames 3D platformer tutorial and was wondering how to implement acceleration and deceleration to the players movement that uses transform.forward. I'm a beginner, sorry if this is something super simple, I just can't wrap my head around it.
 void movement()
     {
         //moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, moveDirection.y, Input.GetAxis("Vertical") * moveSpeed);
         float yStore = moveDirection.y;
         moveDirection = (transform.forward *  Input.GetAxisRaw("Vertical")) + transform.right * (Input.GetAxisRaw("Horizontal"));
         moveDirection = (moveDirection.normalized * moveSpeed);
         moveDirection.y = yStore;     
       
     }
Answer by NoCandyIncluded · Jun 01, 2019 at 02:36 AM
Im not exactly sure what you want, but im assuming you want the movement of the player to be smoother. try this.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 public class Test : MonoBehaviour
 {
 
     private Vector3 moveDirection;
     public float moveSpeed = 5;
     public float time = 1;
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         movement();
     }
 
     void movement()
     {
         //moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, moveDirection.y, Input.GetAxis("Vertical") * moveSpeed);
 
         moveDirection += (transform.forward * Input.GetAxisRaw("Vertical")) + transform.right * (Input.GetAxisRaw("Horizontal"));
         moveDirection = (moveDirection.normalized * moveSpeed);
 
         transform.position = Vector3.Lerp(transform.position, moveDirection, time);
         
     }
 }
Thank you for the solution but I found one myself, I might see if it worked in the old code.
Your answer
 
 
             Follow this Question
Related Questions
Character controller with "instant" acceleration? 1 Answer
Gradual Speed Increase with Variable Input 0 Answers
how to not move on the x axis while not jumping 2 Answers
How can I guarantee a CharacterController never leaves the ground? 2 Answers
Charecter Controller like in Merry Bear game(Cube based game). 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                