Box2D Forums

It is currently Wed May 22, 2013 11:26 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: One way edge shape
PostPosted: Tue Jul 31, 2012 4:23 am 
Offline

Joined: Tue Jul 31, 2012 4:09 am
Posts: 2
Does such a thing exist? In my code, I am using several edges in a chain shape to create complex land shapes. For general purposes, imagine a bean shape comprised of edges with ghost vertices as the basic land type one would see. They work as expected, except the animation engine we use sets the position of characters in our game -- this means, when walking, that some clip into the land. When we allow the physics simulation to take over after this has happened, these characters become partially stuck in the land, which is bad. We would prefer that the edges detect collisions only on one 'side'.

My attempt to solve this problem involved using a contact listener and, if it involved the terrain in any way, using the dot product of the edge's normal (upwards if the vertices of the edge go from right to left) and the manifold's normal for the collision. If this is negative, set the collision to enabled -- otherwise, disable it. It didn't seem to do anything. This is all in begin contact, and for testing purposes I disabled in b2Contact.cpp the line of code in update that sets the collision to true automatically.

I don't know if I can be more clear with my explanation, but my question boils down to as follows:

Is there a way to make edges only detect collisions on one side? I have checked many topics on this forum and they are all too old to be relevant to this anymore. I have seen several of the one-sided PLATFORMS, which is unhelpful to me for a variety of reasons, but mainly because they are usually only relative to the world's positive y direction, and not to one of the directions normal to the edge.


Top
 Profile  
 
 Post subject: Re: One way edge shape
PostPosted: Tue Jul 31, 2012 9:52 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
I think you'll also need to take into account the direction things are moving when they first contact, to decide whether a contact should be enabled or not, rather than just the positions of things. Also bear in mind that the manifold normal points from body A to body B of the contact, and you can't make any assumptions like eg. the ground is always body A.

Backing up a step though, I don't see how this would fit in well with...
Quote:
the animation engine we use sets the position of characters in our game
If this is making things get stuck, it could be because you're teleporting them underground with SetTransform rather than giving them proper velocities? With TOI/bullet bodies and proper velocities, a polygon/circle shape should never tunnel through an edge/chain shape.


Top
 Profile  
 
 Post subject: Re: One way edge shape
PostPosted: Wed Aug 01, 2012 2:35 pm 
Offline

Joined: Tue Jul 31, 2012 4:09 am
Posts: 2
That's exactly why things are getting stuck. The question for us isn't why things are clipping into the land -- it's an unavoidable aspect of our animation engine. Our animator makes 2d animations in a modeling program which we can export into our code; anything but setting the position using settransform would make the skeleton's motion seem unnatural. While clipping is a rarely encountered problem, it is one I think would be perfectly avoidable if only one 'side' of the edge could be collided with. Anything inside the chain of edge shapes would be able to come outside easily.

I'm not sure if taking into account the velocity is the correct approach because it could possibly not be moving. What I want to check is the normal force between the collision and see if it is in the direction of the normal out of the terrain. My attempt to do this involved dotting the vector made by contact points with the normal out of the land -- if it was positive, it meant that the body was outside the land and the collision should occur, and otherwise it shouldn't. I'm not sure why this didn't work.

What other vector could I use from the collision that would tell me which side of the edge shape a body is when a collision is detected.


Top
 Profile  
 
 Post subject: Re: One way edge shape
PostPosted: Thu Aug 02, 2012 6:05 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
You can't teleport something through an edge, tell it that it's not moving, and then expect it to know it should be on the opposite side.
To get around using SetTransform, you could set the velocity so that the body moves to the correct position in one frame. That would mean TOI calculations still work.
Another option might be to use polygons for the ground instead of edges.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group