Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Stop Box2D Sprite Overlap

Author
Message
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 18th Mar 2012 21:48
Hi there. I had a quick question about Box2D in AGK. I notice that when sprites acting under the influence of physics collide, particularly at speed, they appear to overlap briefly before bounding off once another. This seems to give them a squishy look that I don't really want. I'm looking for a way to represent two entirely solid object hitting one another. At no stage should they overlap. I have the same problem with objects acting under the influence of gravity and forces. When lots of objects are being pulled in the same direction, they appear to overlap in their eagerness to get close to the source of the force and this can be fairly protracted if the force is also protracted.

The only thing I found so far was SetSpritePhysicsRestitution() which, whilst making the objects a little less bouncy, doesn't seem to solve the problem of overlap. If anyone has any idea how I can deal with this, that would be great. Thanks.

unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 19th Mar 2012 03:41
The only thing I can think of is that continuous collision detection is not enabled. If you have fast moving sprites, you should try SetSpritePhysicsIsBullet( iSpriteIndex, bullet ), which sets CCD for the sprite (if you haven't already tried that.) Note that this is considerably more computationally intensive so you should only use it if needed.
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 19th Mar 2012 14:18
Thanks for the thought unlikely. I've had a go and I think that helps but it does not solve the problem entirely. I've resorted to doing manual checks for overlap and positioning the objects so that they are no longer colliding. To give you an example of what I mean, here is some code:



If you run that, and it runs as it does on my machine, then you will notice some overlap of the blocks to the right of the screen. However if you change the gravity by uncommenting the commented gravity line and commenting out the current one, then you'll notice that it seems to work fine without any overlap. Any idea what is going on here?

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 1st Apr 2012 23:22
Box2D will struggle to prevent large heavy objects intersecting during collisions as they have a high momentum. To counteract this you could either reduce the scale of the physics using SetPhsycisScale to some small value (so physics think 800x600 is for example 1 meter by 0.75 meters instead of 800 meters by 600 meters) or by reducing the mass of the objects using SetSpritePhysicsMass to some small value so it can more easily stop the object during a collision.

Login to post a reply

Server time is: 2024-05-02 13:32:54
Your offset time is: 2024-05-02 13:32:54