Tilting vehicles

General discussion about Box2D tutorials
Post Reply
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Tilting vehicles

Post by vkreal »

I am very new to box2d, can anyone give an ideas/suggestions on how to tilt a vehicle(motorcycle) up/down when in the air?

Thanks!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Tilting vehicles

Post by iforce2d »

You can use a small ApplyTorque to turn the main body.
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Re: Tilting vehicles

Post by vkreal »

iforce thanks for your suggestion. I am trying to balance a motorcycle on rear wheel simulating a wheely. The problem i am having is when using ApplyTorque not sure when to stop apply force to balance the motorcycle. any ideas? maybe ApplyTorque is wrong approach in this case.


Many thanks!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Tilting vehicles

Post by iforce2d »

Yeah it's a lot harder than they make it look on TV that's for sure. I could only ever do it for a few seconds, even when I had a bike that was quite good for wheelies. These days I just have a little scooter so it's not gonna happen at all with that.

oh... you were still talking about Box2D? :) I think the basic idea remains the same as in the topic here: http://www.iforce2d.net/b2dtut/rotate-to-angle
You need to look at the current angular velocity, as well as the current angle. If the body is already rotating toward the angle you want, then you can apply less torque.
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Re: Tilting vehicles

Post by vkreal »

:) awesome iforce! I will give it a try.
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Re: Tilting vehicles

Post by vkreal »

Hi Iforce2d,

I am trying to achieve same precise(smooth) using accelerometer In your game Downhill Supreme especially controlling player titling. can you give any pointers how to achieve this? i tried using http://www.iforce2d.net/b2dtut/rotate-to-angle but doesnt seem to work that great for me, maybe its the way i implemented it.

Thanks!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Tilting vehicles

Post by iforce2d »

iirc the method used in DHS is like "Using torques" in that tutorial topic, except that the size of the torque is taken from the orientation of the device. There is also a limit on the maximum torque that is applied, so that after the device is tilted more than 45 degrees or so it doesn't make any difference. There is also a minimum limit so that nothing will happen unless the device is tilted more than about 5 degrees, to make it easier for the player to hold the rotation constant. You will most likely need to use the average of the tilt value for the last 10-20 steps, to get a smoother value.
Post Reply