Page 1 of 1

Tilting vehicles

Posted: Sat Jun 15, 2013 1:43 am
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!

Re: Tilting vehicles

Posted: Sat Jun 15, 2013 11:46 am
by iforce2d
You can use a small ApplyTorque to turn the main body.

Re: Tilting vehicles

Posted: Tue Aug 20, 2013 11:32 pm
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!

Re: Tilting vehicles

Posted: Wed Aug 21, 2013 5:38 am
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.

Re: Tilting vehicles

Posted: Wed Aug 21, 2013 5:53 am
by vkreal
:) awesome iforce! I will give it a try.

Re: Tilting vehicles

Posted: Mon Sep 23, 2013 5:47 pm
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!

Re: Tilting vehicles

Posted: Mon Sep 23, 2013 6:11 pm
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.