1
\$\begingroup\$

Illustration: http://s22.postimg.org/7agd30vap/Untitled.png

So the little box is my character. The red arrow shows the current velocity(Some force to right + gravity). Below it are 2 blocks which has the same height. The problem is that my algorithm would false solve the collision normals.(You can see them in green). These would mean that my character would not slide, but will stop in one place.

I'm following this tutorial: http://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331

Is there something I miss and how can I fix this problem?

\$\endgroup\$
0
\$\begingroup\$

This is a non-trivial problem. See http://www.reddit.com/r/gamedev/comments/1w92dm/2d_collision_detection_and_resolution_solving_the/, https://www.iforce2d.net/b2dtut/ghost-vertices .

If all your blocks are axis-aligned, the easiest solution would be to prioritize collisions with normals along the y-axis.

One common solution is to use "rounded" corners for your character box. Another could be to use line segments instead of blocks (if the blocks are supposed to be static) - google "box2d chain-shapes" .

\$\endgroup\$
0
\$\begingroup\$

I solved this problem once by creating a 'rail' (which was just a line located above all blocks.) A rail would exists above all blocks and govern the horizontal and vertical movement of the character. Two rails that touched would connect to each other, allowing the character to move seamlessly from one block to another. If the character touched a block and a rail at the same time, they were moved to the rail and 'locked' to it. If the character touched a block and a rail at the same time, they were moved to the rail and 'locked' to it. While on the rail, walking animation took place, physics was suspended, collision detection with lower blocks was disabled and jump was enabled. If the character walked off the block or jumped, they would 'fall' off the rail.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.