Actor gets stuck on joints between boxes

Discuss issues specific to the Flash/AS3 port of Box2D
robotz
Posts: 16
Joined: Wed May 21, 2008 3:18 pm

Actor gets stuck on joints between boxes

Postby robotz » Mon Jun 15, 2009 6:50 pm

Hi,

I've got an issue where-by my actor gets randomly stuck on the joins between aligned box objects as it slides across them. When it gets stuck no force or impulse will move it.

Image

It's almost exactly the same problem as described here: http://www.box2d.org/forum/viewtopic.php?f=3&t=3069.

However I really don't want to use an edge chain to solve this, because the core of my game relies on quick and easy destruction and movement of the boxes (tiles) that make up the game world.

Is there a setting in b2Settings that would help me out? All "tiles" in the world are 32x32 px in size (so 1m). The actor is slightly smaller than this at 24x24px (0.4m). Tiles have restitution of 0, friction of 1, fixed rotation, allowed to sleep. Actor has friction of 0, fixed rotation, linearDamping 0 and a density of 16 with "SetMassFromShapes" on, not allowed to sleep.

The problem is very sporadic. That leads me to think it's a rounding error or similar, something falling outside those b2Settings boundaries. I just have no idea where or which setting to even start playing with :(

Cheers,

Rich

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Actor gets stuck on joints between boxes

Postby BorisTheBrave » Tue Jun 16, 2009 2:56 am

I'm afraid there isn't much you can do to solve this. It's not exactly a rounding error. I've seen a few different solutions on this board, so a longer search might yield something more to your liking. One possibility is to slightly bevel the corners of your character, or the tiles, or both.

Seeing as you have a regular tiling layout, another option open is to determine when a collision has occurred with an interior edge (which is what is occurring), and take some compensating action.

robotz
Posts: 16
Joined: Wed May 21, 2008 3:18 pm

Re: Actor gets stuck on joints between boxes

Postby robotz » Tue Jun 16, 2009 4:22 am

Thanks for the reply Boris. I did search and read for a while before posting, but the most common solutions seemed to be not using joined tiles like this (combining them into longer rects or polys), using rounded corner objects or using an edge-chain.

Just to clarify: Is what's happening here that the actor has fallen "through" the object and is stuck on the interior edge? What is the most likely reason for them to have got into this situation in the first place? Is it because I have aligned two boxes next to each other, or is it because they are too small in size? Or is it just "one of those things" that all games need to look out for?! :)

I have a custom contact listener that listens to collisions (so I know which block they have hit) - could I use this to tell when they've collided with just the interior? I'm happy to try that out next, and I guess reposition the actor accordingly. I just hope it doesn't make him "jerk" as he moves. Will also try bevelling both tiles and actor too, the reason I hadn't done that already is because in the post I linked to the guy said it made no difference for him.

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Actor gets stuck on joints between boxes

Postby BorisTheBrave » Tue Jun 16, 2009 4:59 am

It's not fallen through, really. It's just that Box2D is (deliberately) imprecise, so near corners it can sometimes hit the other side of the corner. Collisions are only done pairwise, so it cannot know there is something obstructing.

It is one of those things, but not all engines suffer from this, just how Box2D works. It's possible that this will be fixed in Box2D 2.1 when the direction of imprecision is reversed (from inside to outside), but I'm not sure.

robotz
Posts: 16
Joined: Wed May 21, 2008 3:18 pm

Re: Actor gets stuck on joints between boxes

Postby robotz » Wed Jun 17, 2009 3:15 pm

I tried using a bevelled box instead (both for the actor and tiles) and it didn't make any real difference :(

I tried all kinds of different size bevels, but still the actor got stuck on the edges.

Am running out of options now, will have to investigate a different physics system for this game I fear.

But I may try using an edge chain first (and then dynamically rebuilding it as the level changes).

vedder
Posts: 80
Joined: Mon Mar 16, 2009 3:51 am

Re: Actor gets stuck on joints between boxes

Postby vedder » Thu Jun 18, 2009 2:40 am

Does your character necessarily require a square/rectangular bounding box? You might want to try a round bounding box. Or use a curved bottom to minimize the contact size between the player and the tiles.

robotz
Posts: 16
Joined: Wed May 21, 2008 3:18 pm

Re: Actor gets stuck on joints between boxes

Postby robotz » Thu Jun 18, 2009 3:53 am

I could use a curved bottom item, but when I tried using a sphere for the actor instead of a box it had the exact same problem (it would get stuck in the bottom-most part of the sphere where that hit the edges).

Will try it again anyway, but I'm not holding out too much hope!

vedder
Posts: 80
Joined: Mon Mar 16, 2009 3:51 am

Re: Actor gets stuck on joints between boxes

Postby vedder » Thu Jun 18, 2009 7:07 am

if a sphere didn't work than that probably won't work either, I'm affraid.

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Actor gets stuck on joints between boxes

Postby BorisTheBrave » Thu Jun 18, 2009 1:21 pm

This should most definitely not happen for circles. Must be that the original diagnosis was wrong.
You are not using edge shapes? Are you certain your polygons are defined the right way around (long shot, I know). Do you think you could put up a demo to sample the problem.

robotz
Posts: 16
Joined: Wed May 21, 2008 3:18 pm

Re: Actor gets stuck on joints between boxes

Postby robotz » Thu Jun 18, 2009 3:19 pm

I will try a "curved bottom" actor and then upload a demo for you certainly, with that in place.


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 1 guest