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

Post Reply  Post Oekaki 
 

Posted By Message

vetmora120



Registered
  1/7/2010
Points
  281
5th July, 2012 at 7/5/2012 7:52:50 AM -

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?

 
The universe of Vetmora.

SolarB



Registered
  12/26/2011
Points
  214
5th July, 2012 at 7/5/2012 1:03:52 PM -

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



 
n/a

vetmora120



Registered
  1/7/2010
Points
  281
5th July, 2012 at 7/5/2012 1:53:30 PM -

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.

 
The universe of Vetmora.
   

Post Reply



 



Advertisement

Worth A Click