Hi
I am using Box2D (c++) for a game project, where the player basically runs around in a maze. The level is designed as a SVG file, the paths are interpolated into points, and depending on a set resolution, the walls are created point by point. Now what I do is create a b2Box shape (with a constant y-extent) from one point to the next, as long as there are points. When the maximum number of shapes is reached, I add the created shapes to a body, and keep going in a new body... This creates a wall of few bodies (right now about 2 or 3, depending on the set resolution) , each with quite an amount of shapes ( max. 256 per body), with lots of "corners" in it, right where to box shapes intersect.
My problem is, that my player body ( a circle shape) keeps getting stuck, as soon as it is run into a corner, having two contact normals squeezing it in into the corner. Unfortunatley, in this game, the player will not be able to move backwards (for game design reasons). So he is stuck in there forever. Even though, I still tried to change the x and y coordinates by hand (by manipulating the values in runtime using defined keyboard buttons), and noticed, that box2d changes the players position back to the corner, to where he got stuck in the first place - right after the keyboard input changed the x or y value for the fraction of a second. So I assume, the player is caught inbetween two contact normals and there is no getting out of there.
Is there any way I can avoid the player getting stuck at those box intersections? The first thing that came to mind was to take the average of all contact normals and then using an impulse or such to move him along that normal out of the deadlock. But probably I am doing something ridiculously wrong and someone can tell me what to do better?
Thanks for reading this way-to-long post! 🙂
_R
I am using Box2D (c++) for a game project, where the player basically runs around in a maze. The level is designed as a SVG file, the paths are interpolated into points, and depending on a set resolution, the walls are created point by point. Now what I do is create a b2Box shape (with a constant y-extent) from one point to the next, as long as there are points. When the maximum number of shapes is reached, I add the created shapes to a body, and keep going in a new body... This creates a wall of few bodies (right now about 2 or 3, depending on the set resolution) , each with quite an amount of shapes ( max. 256 per body), with lots of "corners" in it, right where to box shapes intersect.
My problem is, that my player body ( a circle shape) keeps getting stuck, as soon as it is run into a corner, having two contact normals squeezing it in into the corner. Unfortunatley, in this game, the player will not be able to move backwards (for game design reasons). So he is stuck in there forever. Even though, I still tried to change the x and y coordinates by hand (by manipulating the values in runtime using defined keyboard buttons), and noticed, that box2d changes the players position back to the corner, to where he got stuck in the first place - right after the keyboard input changed the x or y value for the fraction of a second. So I assume, the player is caught inbetween two contact normals and there is no getting out of there.
Is there any way I can avoid the player getting stuck at those box intersections? The first thing that came to mind was to take the average of all contact normals and then using an impulse or such to move him along that normal out of the deadlock. But probably I am doing something ridiculously wrong and someone can tell me what to do better?
Thanks for reading this way-to-long post! 🙂
_R