• Advertisement
Sign in to follow this  

Some odd Box2d collisions when switching the width and height of a body

This topic is 762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I'm using Box2D as a physics engine for the game I'm creating for my Game Programming class.

 

Just a quick background, I'm using C++ with SDL2, an ECS and (as far as I know) am scaling everything properly in Box2d.

Now on to the problem. I have two bodies, one which is a static body and one which is a dynamic body. The static body is 96x96 and I'm switching the dynamic body between 96x96 and 96x64 for testing purposes.

 

When both bodies are 96x96, collision works find and I have no problems. When the dynamic body is 96x64 I'm getting some odd collisions. I'm not quite sure I understand what actually is happening.

 

Sharing some screenshots would probably better explain my issue. 

http://imgur.com/a/mxVIS

 

This, is also my code. It contains how I'm creating bodies, rendering the debug and moving the bodies.

http://pastebin.com/KkVzBiXR

 

Any help would be greatly appreciated. Thank you very much

Share this post


Link to post
Share on other sites
Advertisement

Looks to me that the position you are placing it is at the top left corner of the sprite, if that's the case try offsetting the positions by the width and height of your sprite.

 

Assuming that +X is to the right and +Y is going up:

 

X = X + ( width * 0.5f )

Y = Y - ( height * 0.5f )

Edited by Daganar

Share this post


Link to post
Share on other sites

Sorry for he late response. I haven't gotten the chance to look back.

 

I am doing that in the ToSDL2Coordinates method.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement