- Home /
Accelerate and brake a car without wheel collider
I am trying to make a simple car game in Unity. I want to make a car controller such that it can move forward and in X direction.
for moving car in X direction i am using transform.translate.x i can use the same for forward but i want it to accelerate its velocity relatively with time and to stop slightly on applying brake which is not possible in transform.translate.forward help me in doing this.
Answer by mlnczk · Dec 05, 2018 at 07:43 AM
private Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
}
void Update(){
if(Input.GetKeyDown(KeyCode.Space){
rb.velocity *= 0.9f; // it will slow down until it stops completly, if you multiply it by lets say 1.1f then it will accelerate
}
}
If you want to have maximum speed you can change rb.velocity.magnitude and if it increases certein speed then you can stop accelerating etc.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
simple drift car movement 0 Answers
2D Car Physics for Drag Race Game 1 Answer
How do i Update a Transforms Position, and how do i have objects face along a spline?? 1 Answer