Currently I'm making a racing game.
I move my cars with the Transform.translate
class.
Now the thing I want for my cars is not to move through each other.
I attach colliders and a RigidBody to my player car and it's working.
But my problem is that each time my CPU cars and player car encounter with each other, my player car shows unrealistic behavior like moving out of the screen or throwing away.
I know this is part of the physics engine behavior but is there a way to make the RigidBody only do one job and make objects not to move through each other not to add other physics behavior?
Any ideas?
There are just few problems:
1.You don't move Rigidbody with transform.translate
. When you do this, colliders will go through other colliders.
You move Rigidbody with Rigidbody.AddForce
, Rigidbody.velocity
and Rigidbody.MovePosition
. By moving Rigidbody with these methods, collision should be functioning properly.
2.You are not even supposed to move the Rigidbody
of the car.
Use WheelCollider
. There are many online tutorials on how to set them up on the internet but Unity's documentation is fine too.
WheelCollider.motorTorque
is used to move the car forward or backwards.
WheelCollider.steerAngle
is used to steer the car.
WheelCollider.brakeTorque
is used to brake the car.
If you need further help, you can find a fully working WheelCollider
samples here.