I’m making a mobile game in which all players control cars. However, because of the restrictions of the mobile platform, I have decided not to use Wheel Colliders given of their processing cost.
Instead I have a pretty basic script that rotates the car and moves it forward from input.
to move forward transform.Translate(Vector3.forward, etc,etc); to turn transform.rotation *= Quaternion.AngleAxis();
I’m very happy with the way this works except for one thing: velocity/acceleration is not handled.
To fix the horizontal acceleration and deceleration of the car, I modified the car movement script to slow down or speed up the car when it starts or stops moving. The car properly accelerated forwards, but would not properly decelerate.
A bigger issue I have is falling. Gravity does its job well, but moving forward is flawed. Because of the way the script moves (the car’s forward is Vector3.forward) the player can simply tilt the car up while in the air, so that the car’s ‘forward’ is really upwards and they player never falls down.
It seems like I’m missing something, and there is either a better way to move the car, or a way to let the Physics engine handle the car’s velocity.
I’m just looking for the behavior of cars with Wheel Colliders, but without the Wheel Colliders.
Your not using the physics engine, when you translate your object.
You can
A, add collision detection to check if the car is on the ground, and apply a downward force, disable turning and acceleration/deceleration.
B, Add a rigidbody to your car then convert the Transform.Translate to a Rigidbody.AddForce, and Rotate to Rigidbody.AddTorque
These should give you a closer response to what you desire:
A can be more controlled with less physics overhead.
B lets the physics do the work but can take more to get the feel right.
Hmm. That seems like it should be perfect, but the behavior I get isn’t what I want. The inertia is far too much, and more importantly, when the car rotates, the force keeps pushing it in the direction it was going, so turning is very hard.
Ah, thanks, this might also solve my problem. I’ll try tonight!
[EDIT] So it did. To complete the picture here, if you want to use a kinematic rigidbody (tag the kinematic checkbox in the rigidbody properties), and want to move it around and still affect physics, use rigidbody.MovePosition() and rigidbody.MoveRotation().