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:
Objects "sliding" with polygon collision detection
Objects "sliding" with polygon collision detection
- Attachments
-
- example.love
- (4.68 KiB) Downloaded 138 times
Re: Objects "sliding" with polygon collision detection
What are you doing to detect collisions, and what is your final goal? I don't have the ability to look through your .love too well at the moment but it seems like you might be using too complex a solution for what you want to do. Complex polygon to polygon collision detection isn't really necessary in a lot of game situations. You might be able to accomplish what you want by abstracting the circle shape down to a set of points instead of using (what I assume to be) a distance based algorithm.testtext_ wrote: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:
My preferred solution for platformers is to ALWAYS apply gravity, and when an object is on the ground I push it up using a while loop and set the vertical speed of the object to 0. Here's some psuedocode. Imagine p1 is the player object, the circle in your demo. In my scenario, p1.x is the center the of the circle, and p1.y is the bottom of the circle.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.
Code: Select all
p1.ySpeed = p1.ySpeed + p1.gravity
p1.y = p1.y + p1.ySpeed
while(collideWithWorld(p1.x, p1.y))
p1.y = p1.y-1
p1.ySpeed = 0
end
True.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.
About abstracting the object down to points, if you have 4 points for an object, then you 'pop' it out in whatever direction the points are in. If the left point is hit, pop the object out to the right. If the top point is hit, pop it down.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.
Does that help any? I might be able to give more helpful advice if I knew what you were trying to create. Also hope I didn't just explain a bunch of stuff you already knew haha.
Re: Objects "sliding" with polygon collision detection
Maybe using points could work better for this, but I already had this polygon collision library, so I thought that using it could be easier than separately implementing it with points/rays.Skeiks wrote:What are you doing to detect collisions, and what is your final goal? I don't have the ability to look through your .love too well at the moment but it seems like you might be using too complex a solution for what you want to do. Complex polygon to polygon collision detection isn't really necessary in a lot of game situations. You might be able to accomplish what you want by abstracting the circle shape down to a set of points instead of using (what I assume to be) a distance based algorithm.
I guess that one solution to that would be to reset the position if the slope is too large, and start applying gravity again.Skeiks wrote:True.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.
I might just do that (although that method isn't without issues, either). As I said above, my main reason for using polygons was that I already had it implemented for something else.Skeiks wrote:My preferred solution for platformers is to ALWAYS apply gravity, and when an object is on the ground I push it up using a while loop and set the vertical speed of the object to 0.
...
About abstracting the object down to points, if you have 4 points for an object, then you 'pop' it out in whatever direction the points are in. If the left point is hit, pop the object out to the right. If the top point is hit, pop it down.
It helped a little; I'm thinking of how to implement movement in a platformer and I'm probably really overthinking it.Skeiks wrote:Does that help any?
But my main reason for this post was that I just became curious if there's a known solution for polygon "sliding" with gravity, since physics engines use polygons and don't seem to suffer from this.
Who is online
Users browsing this forum: No registered users and 3 guests