Objects "sliding" with polygon collision detection
Posted: Fri Mar 06, 2015 1:52 am
When using polygons and circles for collisions between platforms and other objects, is there a way to have objects fall when in the air, but not "slide" down sloped platforms (this is using my own collision detection code, not love.physics)? This happens because the object is "popped out" of the platform at an angle when it is sloped, causing it to move sideways, but I can't think of a good way to fix it that doesn't cause other problems:
1. Stop applying gravity when on the ground. This will make it impossible to tell when the object walked off the edge of the platform.
2. Once the object hits a platform, start moving it in the direction of the previous frame's collision instead of adding gravity. This will cause the object to "stick" to the platform, which is not a big problem, except objects will start running down walls even when they are supposed to fall off of the sharp corner of a platform.
3. Add code to "pop out" the object in a specific direction (in this case up), instead of the shortest way. This would be ideal, until the object hits a wall, and suddenly reappears at the top of the wall.
What is the recommended way to handle this? I have a demo attached that demonstrates the issue:
1. Stop applying gravity when on the ground. This will make it impossible to tell when the object walked off the edge of the platform.
2. Once the object hits a platform, start moving it in the direction of the previous frame's collision instead of adding gravity. This will cause the object to "stick" to the platform, which is not a big problem, except objects will start running down walls even when they are supposed to fall off of the sharp corner of a platform.
3. Add code to "pop out" the object in a specific direction (in this case up), instead of the shortest way. This would be ideal, until the object hits a wall, and suddenly reappears at the top of the wall.
What is the recommended way to handle this? I have a demo attached that demonstrates the issue: