- Home /
How to make a rigidbody move with wheels?
I have a rigidbody which i want to make controllable with the use of wheels (2 or 4 wheels with tank style steering(eg when i press the left arrow key one wheel goes forward the other goes backwards)) and not a character controller. But i don't have a clue as to how to do it. I know that there are similar questions on here but they haven't really helped.
any help would be really appreciated.
Here is a reference page to some videos on using Unity's physics engine. Video #7 is on the Wheel Collider.
http://www.3dbuzz.com/training/view/unity-fundamentals/physics
Actually i can't use wheel colliders as without a physic material the wheel will fall through the floor and wheel colliders don't use physic materials as far as i am aware. Edit: Actually i have found a way to use wheel colliders so i shall have a look at the video.
I have watched the Wheel Colliders Video from that site. and it was very informative. If you take the time to check it out, I think that you will agree.
I've found a way to make a wheel move but the wheel (with the rubber physic material and a rigidbody) doesn't get a proper grip on the floor(metal physic material). It just spins round quickly but barely moves anywhere.
@VolureDarkAngel I haven't watched the entire video yet as i found a script segment which allows an object to spin on the y axis. which i am having trouble with(see comment above) using with the wheel.
Answer by Xtro · Jul 29, 2013 at 08:03 PM
You should use hinge joints between the body object and the wheel objects. All objects has to have their own colliders and rigidbodies.
If you can attach the hinge joints correctly, your car will move on the wheels. You can apply the material to wheel objects' colliders.
I prefer simple mesh colliders for wheels.
Steps :
Right now, I'm at work, so I can't test it m self but it should be like this:
1)Create the car body with a cube(and a collider on it)
2)Add a rigidbody to it.
3)Create the wheel with a cylinder(and a mesh collider on it)
4)Add a rigidbody to the wheel.
5)Select the collider mesh as a cylinder mesh.
6)Don't parent the wheel under the body in hierarchy window. They must be separate objects.
7)Add a hinge joint on the wheel.
8)Set the axis direction according to where it must be (you can see a orange little line as an axis in the editor window).
9)Set the connectedBody to the car body object.
By doing these, body and wheel moves together. Wheel rotates and body moves on it. You can apply motor force to the hinge joint. So it can basically act like a motor too.
I tried what you said and it worked except i can't make the wheels move.
EDIT: Okay i've managed to get the wheels to move but i don't know how to control them
You can write a script to modify the motor values on the wheels. I assume you can write script.
get the hinge joint component from the wheel game object. enable or disable its motor. or change its velocity. if you want to make the car turn left or right, you should rotate the wheels to left or right.
Ok. i'll try and write a script for it. Thanks alot for all of your help!
Answer by Imankit · Jul 30, 2013 at 11:19 AM
Posting an asset link shouldn't be an answer. $$anonymous$$aybe you can mention it in a comment below the question.
OOPS!! Here is a massage I got for Unity Car
Your country is blocked due to the U.S. Government restrictions.
Any advice how to get it..?
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Aircraft Control 1 Answer
Rigidbody.AddTorque/AddForce Question. 1 Answer
Why is my push rigidbody script not effected by mass? 2 Answers
How to prevent Wheelie on WheelCollider 2 Answers