Collisions "snap" the player to align with individual tiles

I have used the code from Resolving kinematic collsions in Defold for resolving kinematic collisions, but when I test it in my platformer game, I don’t understand why it’s “snapping” to the individual blocks in the game world.

Here’s a video to demonstrate what I mean:

I don’t understand vectors well enough to know what the problem is. Any ideas?

Is there any way that I can check for a collision in the update section at a specific point? For example:

-- The update loop
if collision(x, y, {collision_parameters}) then
    
end

Right now the only solution I can see possible is resolving the correction vectors to prevent the player from passing through a wall.

This has been a common issue for Defold users. It’s to do with the way the collision normals are presented when you land on the boundary between two tiles. Have a look at this thread for more about that… Wall-clipping collision issue

I’ve made a bunch of platformers and to be honest, I’ve just put up with it. It does help to have a circular collision shape for the player instead of a box.

4 Likes

Thanks. I checked through the forum and I didn’t realize there’s been many similar threads. I have moved on to try raycasting. Do you have any experience with implementing raycasting for platforming physics/collisions? I would love to know what things you may have come up with.

So far I have the player casting 2 rays based on what direction the player is moving. If the player is moving up/down & left/right, it will cast 4 rays per frame to check for collisions. The only problem with that now is the player can now land on a platform, then continue to float in the sky before jumping again. I was thinking of retaining the old velocity in the direction the player was moving at the moment of impact with the platform. That way, it should check if the player is still on the platform if he walks off of it.

In my opinion, raycasting is not going to save you from those little irritating glitches. I wrote a platformer extension a while back that heavily relied on raycasting after experiencing the little glitches with collision shapes. I ended up removing it from GitHub because I couldn’t in good faith keep something up that had little issues here and there.

But at the same time maybe I’m just not smart enough to make proper platforming physics. The best solution so far I’ve seen is to use a circular shape like Ben James mentioned in an earlier post, but even then you still get side effects like your player pushed diagonally when on the corner of a 90 degree tile. Well, there are other annoyances, but I can’t remember them at the moment.

It’s interesting because I’m easily able to implement solid platformer physics when making games or prototypes without Defold, like doing collision reaction in a plain C++ / (choose your graphics library). I feel like it just comes down to how collision messages are posted in Defold. You get many collisions per frame, but they don’t come at the same time so it’s a little weird to sift through which are “valid” and which aren’t. I don’t know, pretty confusing. I avoid platformers in Defold.

Yes, I have found that the event based collisions (messages) feels odd with how it goes through each colliding object separately. I’ve used GMS2’s collisions and they get the job done, allowing me to make multiple collision checks on demand. I don’t have a problem with resolving the collisions in the case the player goes through the wall a bit, but it seems too difficult for me to do such things correctly with Defold.

I love how Defold is easily made available to play on a bunch of platforms, and it’s free to use. Open source is nice too, although I’m not at the point where I can make use of that sort of thing.

Seeing that there are no solid examples without issues like these, even with the platformer sample on Defold https://github.com/defold/sample-pixel-line-platformer has problems with the creases between each tile which messes up the surface normals.

I just am not sure Defold is what I need right now. I really want to make a platformer with reliable physics that are predictable and accurate. I’ll keep trying with what I’ve been working on and see how things go. But I might have to move to something else for now.

Thanks for your response. I have seen potential with Defold with pretty nifty games out there. The collisions are good for most cases, but I guess platformers require extra attention? I think even a function to manually check for collisions would change things dramatically. So raycasting helps with achieving such results. But as I’ve experienced today, it takes a lot of figuring out to get all of the proper points and directions to get the right collisions checks.

It’s really just pixel-perfect collisions that are unrealistic. Haven’t had a problem otherwise. Unfortunately a lot of games are low-res pixel art games, so this issue comes up a lot.

Achieving pixel perfect collision does not take a lot of brainpower. It’s quite easy and the algorithms are time tested. I wish I could recall the exact reasons it’s so hard in Defold, but it has been a while so I’d have to think it through (but I don’t have the time :wink:)

It’s another thing to note how even @benjames171, who has made several Defold platformers, still “just has to put up with it.” I think that’s more good evidence that there’s a real problem here.

3 Likes

I’ve spent a few nights testing and rethinking how collisions work and how to maybe “manually” figure them out. But the most I’ve had is taking the player’s y position and adding half the sprite size to it to get the edge of the sprite. Mostly works using this logic with raycasting. I had no luck with the other collision messages.

I definitely agree with you that it still does things well if not getting the perfect collisions. Pixel perfect collisions are what I am hoping to achieve, regardless of which engine I use. When it comes to pixel art games, pixel perfect collisions feel so good. I’m sure it adds to the gameplay of a platformer, as I know I would feel like I have more control over the player in that case.

Oh not necessarily. There’s definitely cases when you don’t want pixel perfect collisions. If you look up the concept of Coyote Time or Coyote Jump you’ll find that many platformer games will let the player jump a fraction of a second after walking off a platform.

Also in many shoot em up games you make the player hitbox smaller than the graphics.

Another example from 2d fighting games where hitboxes do not line up with the graphics: https://game.capcom.com/cfn/sfv/column/131422?lang=en

3 Likes

Oh. I must have the wrong idea of what pixel perfect collision is. I thought it meant that the collision mask would be flush with the mask of a wall or floor type object. Then in this case, I don’t want pixel-perfect collision.

But this is something you can achieve in Defold. Using raycasts should work quite well for this.

Oops, yeah I hadn’t realized pixel perfect collisions referred to each and every pixel on an image. Anyway, I think I will keep trying with the raycasts and see how things go.

I’m kind of having a hard time making use of the raycasting. Is there any example or tutorial for using raycasting in this case?