The Daily Click ::. Forums ::. Klik Coding Help ::. Box2D help
 

Post Reply  Post Oekaki 
 

Posted By Message

vetmora120



Registered
  07/01/2010
Points
  273
5th July, 2012 at 05/07/2012 07:52:50 -

Hello!

I posted this on the Clickteam forums but havn't had any replies.

For weeks now I have been trying to create a good top-down car physics engine. I'm using Box2D v2.0.0. I know about the car example in the Box2D testbed, which is very simple and doesn't demonstrate sliding, handbraking, etc. The Chipmunk one does, however, but I want to work with Box2D v2.0.0 as it contains kinematic bodies and is the most updated version. I even tried converting the Chipmunk one into the latest Box2D version, but it didn't work well...

I have found various car physics articles and tutorials for games but have no idea whats best and am not the best at converting the formulas into MMF2. Some of the ones I have found are as follows:
http://www.asawicki.info/Mirror/Car%...r%20Games.html
http://phors.locost7.info/contents.htm
http://www.iforce2d.net/b2dtut/top-down-car
Oh and how cool is this - click the next example button a few times.
http://quickb2.dougkoellmer.com/bin/qb2DemoReel.swf

I don't want it to be overly complicated, meaning I don't want things like weight transfer, gear shifting, etc. I do want just the normal accelerate, decelerate, braking, handbraking, turning, sliding and maybe drifting which would be similar. Of course, I realise this still won't be easy though.

You can get Box2D version 2.0.0 from here: http://dark-wire.com/store/extlist.php

Anyone able to point me in the right direction?

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
5th July, 2012 at 05/07/2012 13:03:52 -

I'm only a beginner at Box2D but wouldn't it be just a matter of applying forces or impulses to whatever joint/body is necessary based on the values and formulas that are added/subtracted/stored in variables? Sorry if you're way past this, but a quick glance at those articles suggests to me that that would be the way to go, so for instance:

void updateTurn(int controlState) {
float desiredTorque = 0;
switch ( controlState & (TDC_LEFT|TDC_RIGHT) ) {
case TDC_LEFT: desiredTorque = 15; break;
case TDC_RIGHT: desiredTorque = -15; break;
default: ;//nothing
}
m_body->ApplyTorque( desiredTorque );

would become:

+on left arrow
--> (box2d) - apply torque 15 (body->velocity->torque to object)

+on right arrow
--> (box2d) - apply torque -15


And if it's a formula, store that in a variable, run the necessary calculations on it from some event and then apply the variable as force/impulse etc.


As for the more complicated stuff, well...


I implemented this kind of thing in a flocking example I made - not using Box2D - but it might still be helpful to you:

http://community.clickteam.com/showthread.php?t=71345

using this article:

http://www.vergenet.net/~conrad/boids/pseudocode.html



 
My Open Source Examples: http://bit.ly/YyUFUh

vetmora120



Registered
  07/01/2010
Points
  273
5th July, 2012 at 05/07/2012 13:53:30 -

I'm kinda passed this already, but it has helped to simplify the process and put some things into perspective. Especially for trying to break down the C++ for MMF2.

I mean, the Chipmunk car physics engine would be perfect for what I want, but I just can't seem to get that to work in Box2D. Thanks for the help, SolarB. I'll see what anyone else has to say.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click