How could I make my character move forward smoother?
So that it takes a while until the character is moving full speed and also takes a while to stop.
This is my current code for moving forward.
// WALKING
if(isWalking == true){
transform.Translate(Vector3.forward * Time.deltaTime * walkSpeed);
}
You could try linear interpolation:
if( isWalking ) {
currentMoveSpeed = Mathf.Lerp(currentMoveSpeed, walkSpeed, smoothTime * Time.deltaTime);
transform.Translate(Vector3.forward * currentMoveSpeed * Time.deltaTime);
} else {
currentMoveSpeed = Mathf.Lerp(currentMoveSpeed, 0, smoothTime * Time.deltaTime);
}
we are interpolating between the “currentMoveSpeed” and “walkSpeed” to smooth the beginning of movement and from “currentMoveSpeed” to 0 to smooth the end of movement. “smoothTime” would be the variable to control the acceleration (in units per second).
Hope this helps!