I am currently making a car controller in unity and looking for a way to move my car while being able to correctly collide with obstacles. I also want the car to be able to drive on uneven roads. The road is kinematic while the obstacles have gravity and are not kinematic.
1 – I tried using transform.Translate but as expected, it just ended up ignoring colliders.
verticalInput = Input.GetAxis("Vertical");
transform.Translate(transform.forward * speed * verticalInput * Time.fixedDeltaTime);
2 – I then tried using Rigidbody.MovePosition() while the car has gravity and is not kinematic. The car was able to correctly drive on uneven roads but wasn’t successful in pushing away the obstacles. The obstacles were pushed below the car (between the wheels).
verticalInput = Input.GetAxis("Vertical");
rb.MovePosition(rb.position + transform.forward * speed * verticalInput * Time.fixedDeltaTime);
3 – I tried using Rigidbody.MovePosition() while the car is kinematic with self-coded gravity. The car fell down and ignored the road collider. But I noticed that this approach made the car interact well with the obstacles.
verticalInput = Input.GetAxis("Vertical");
rb.MovePosition(rb.position + transform.forward * speed * verticalInput * Time.fixedDeltaTime);
4 – I tried altering the Rigidbody’s velocity while the car is not kinematic. The car tumbled instead of moving like an actual car. The car also can’t be steered.
verticalInput = Input.GetAxis("Vertical");
// Move the vehicle
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, speed * verticalInput * Time.fixedDeltaTime);
5 – I used Rigidbody.AddForce() while the car is not kinematic. I had to set the speed to like 100000 then the car started very very slow then accelerated to a very very fast speed. (I want the car to move like a transform.Translate)
verticalInput = Input.GetAxis("Vertical");
rb.AddForce(transform.forward * speed * verticalInput * Time.fixedDeltaTime);
Btw, I’m using Unity 2020.1