- Home /
Question by
ForgottenXGamer · Dec 14, 2017 at 01:10 AM ·
c#unity 53d
How to move 3D character with acceleration and deceleration and face in direction of movement
Here is my current code with no acceleration or deceleration. I removed what i had because it was a mess and would like to start from scratch.
public float AccelerationTime = .3f;
public float DecelerationTime = .4f;
public float MaxSpeed = 1;
public float RotationSpeed = 90;
Camera cam;
public void Move( Vector2 input )
{
cam = GameUtils.GetCamera();
Vector3 movement = cam.transform.TransformDirection(input);
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.LookRotation(movement), RotationSpeed);
transform.Translate (movement * MaxSpeed * Time.deltaTime, Space.World);
}
Movement works fine in all directions based on my camera without acceleration or deceleration but when i try to rotate the character to face the direction its moving it gets angled upward or downward when moving any direction other than left or right.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612144542im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do i Achieve mesh Extrusion? 2 Answers
How do i cast mesh like a linerenderer? 0 Answers
How do i instantiate a Vector3[] ?? 2 Answers
BoxCast to tell if player is grounded 0 Answers
How do i do this type of spline?? 1 Answer