# Car Game Physics

Hi everyone!

i’m whiling to create a game like this one

But sadly i cant find any information about Wheel Joints 2D besides the documentation of unity.

I handed myselft to get a simple car with the wheels, and add a motor force on input, but if the car jumps, when the wheels touch again the floor everything get broken and the car gets punched to the air like a rocket, rotation over himselft and the wheels and etc… really really broken xD

Anyone have some information or some steps to get a car working with a wheel and a suspension?

Ant help would be really appreciated!

Are you still willing to create something like it, or have you already done it?

I have done something similar based on a korean tutorial:
http://mobiletou.ch/2014/06/unity-4-5-で追加された-wheel-joint-2d-の使い方

but isnt working okay for me

hey, I was looking at that tutorial too…
The funny thing about wheelJoint2d is that it shouldn’t be attached to the wheel (as mentioned in that tutorial), because otherwise you have to change the angle of suspensions (as mentioned there too) and I’m not quite sure if this isn’t the root cause of your problem.

So I would suggest you to try and change it.
Add the wheelJoint2d to the body of the car and add the wheels as connected rigidbodies in wheelJoint2d. place the wheelJoint2d as in tutorial (so the connected rigidbody and the anchor are at the same place in the middle of the wheel).
Now you can try either to add speed to Motor of the front wheelJoint2d or to addTorque to the front wheel directly.

Cool, i will try that way.

did you make it work? cause i’m really lost with this, i have a lot of cool assets that a friend graphic designer gave to me, so i could make a game like this one, but i’m really lost

Thanks!

It works for me to some extent. I have a problem which is that when I jump and the car is in the air, it slowly rotates into some direction and when I stop the motor/front_wheel, it starts to rotate in different direction.

It looks like some problem with angular drag or maybe with mass of the wheels, because if I don’t change the motor speed in the air, it looks quite ok… fly in some direction and land and go on.
I’m going to test a few different things, like changing the mass of body and wheels and maybe moving the car with adding torque to the wheel’s rigidbody (instead of using motor). Will see if that will change anything. (I’m counting on the mass, to be honest:)

The thing i dont quite understand (Maybe because i’m not looking at it with unity atm) is that if you attack the wheeljoint2d to the car body instead of the wheels, how do you make to add motor force to the wheels, and get the wheels to rotate when adding the motor force? (do you make this adding it the the wheeljoint attached to the car?)

the thing is, that wheelJoint2d is designed in a way that the motor add torque (or speed or what) to the connected rigidbody and not the the attached gameobject (the anchor). to say it more clearly it gives the rotation to the blue full_circle, not to the blue empty_circle (blue circles, which you see when select gameObject with wheelJoint2d).

Also that is the reason why in that tutorial it has the change of the spring angle (in wheelJoint2d). Because when you attach it to the wheel it rotates the other part, the car_body, and so you have to adjust the spring all the time

At least that is how I understand that.

Cool i’ll check on this when i get home!

I’ll share my experience here if i get something working good

You where rigth, The body have the 2 wheelJoint2D with CollideConnected triggered and the connected rigid body linked to both wheels, and not a single line of code and the car is working.

i have to tune the suspension now, it feels like a car with no suspension xD and i dont know why if i add possitive force to the motor, the truck goes back, and if i add negative force it goes forward xDDD

Thanks dude! i’ll post any progress on this

I’ve managed to get this, but i dont know why, the motor moves forwards only with negative force

And the wheels are turning really fast but the car moves really slow

try to add physics materials to the wheel collider and the ground

i did, even with a material with 10000 on friction the car still doesnt move fast enough

also you could apply a force with the local “right” direction of the car if your car is grounded

Just checked doing addforce, and the car isnt moving, it only applies the force to the body of the car (or the wheels, tested both cases) and it just lean forward or back and stays on the same spot.