Box2D.. Can't make this circle move halp.

Subscribe to Box2D.. Can't make this circle move halp. 8 posts

avatar for ErlendHL ErlendHL 1313 posts
Flag Post

Hey. I figured out I need to implement Box2D in my game. So I have this test project first when I basically try to draw a ground and a ball that should fall down…
I wrote 120 lines of code to add those and draw them. But they don’t move at all. I’ll post my code to pastebin: http://pastebin.com/VVmXugyP

You should look at the init funciton and the update function. Drawing works. It’s just that I’d expect that the ball would fall. It stays still in the air.

Any help would be much appreciated!

 
avatar for DPbrad DPbrad 1197 posts
Flag Post
circleBodyDef.type = b2Body.b2_dynamicBody
 
avatar for ErlendHL ErlendHL 1313 posts
Flag Post
Originally posted by DPbrad:

circleBodyDef.type = b2Body.b2_dynamicBody

Couldn’t find type in circleBodyDef and neither b2_dynamicBody in b2Body, but this is the closest I could come:

circleDef.type = b2Body.e_dynamicType;

And it threw Error #1009 (null object reference) from inside the b2Body class ._.

Using Box2D 2.02 btw.

 
avatar for DPbrad DPbrad 1197 posts
Flag Post

You may need to call SetMassFromShapes on your circle b2Body then if your using 2.0.2…

EDIT: After line 56 in your pastebin code.

 
avatar for UnknownGuardian UnknownGuardian 8140 posts
Flag Post

Random note would be I think your gravity vector is also wrong. -10.0 will make it float to the top I think.

 
avatar for player_03 player_03 1249 posts
Flag Post
Originally posted by ErlendHL:

Couldn’t find type in circleBodyDef

Are you using box2Dflash?

I checked, and type is defined on line 67 of b2BodyDef. Additionally, SetType() is defined on line 897 of b2Body.

For some reason, neither one appears in the online documentation, but they’re definitely there.

 
avatar for ErlendHL ErlendHL 1313 posts
Flag Post

Thanks all!
I changed the init function to this

It now looks like this. I think the movement looks really crappy, and when it finally lands on the ground, it keeps ‘shaking’…

 
avatar for DPbrad DPbrad 1197 posts
Flag Post
Originally posted by player_03:
Originally posted by ErlendHL:

Couldn’t find type in circleBodyDef

Are you using box2Dflash?

I checked, and type is defined on line 67 of b2BodyDef. Additionally, SetType() is defined on line 897 of b2Body.

For some reason, neither one appears in the online documentation, but they’re definitely there.

It is in Box2D 2.1, but Erlend is using the old version and I don’t think that “type” property of a “b2BodyDef” was implemented in the old version.

Regarding the shakiness Erlend, I would recommend just using the newer Box2D (2.1a). It contains a lot of fixes over the old version and you dont require as many lines of code for the same functionality you desire.