This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

pass-through bottom sloped tile collision

pass-through bottom sloped tile collision
by on (#137359)
I want to know if there is a way of doing this simple enough for tutorials, but still very accurate.

An easy way I found is to have 2 modes. One is for moving on the ground, by looking up the ground height at the x pixel of the tile and the tile above it, and snapping it to the whatever ground is heighest. The other mode is for objects not on the ground, at it works the same except it is checked if the x coordinate has gone down through the ground. This has two problems. You can't have platforms directly above each other, or else the character will pop, and you can't move an object up at a slope that is less steep than the platform, or else it would incorrectly go through the platform.

I have another way that is more complicated. Instead of just checking if it went down through a point, it instead checks if the previous position was above the previous positions ground height. If it advanced a tile to the left or right of the previous frame, it splits it up into two parts. The first is move it to the left or right side of the tile, and then continue it to it's destination. If a destination is one block down and right of the previous block, and it was right above an up going slope, it will end up 2 tiles above the destination, requiring it to check 3 tiles instead of 2.

There must be an easier way than this, that I'm just not getting. Anyone have advice about this?
Re: pass-through bottom sloped tile collision
by on (#137412)
I'm surprised noone has gave me feedback on this.
Re: pass-through bottom sloped tile collision
by on (#137414)
how I've done jump-through collision in the past:

1. ignore collision if velocity is not downward OR if starting position this frame is below the surface line
2. use collision if velocity is downward AND starting position this frame is above the surface line

another way of saying this is collide only if the surface line is crossed this frame in a downward direction
Re: pass-through bottom sloped tile collision
by on (#137427)
Be careful you don't end up with this glitch from Super Mario World:

Notice how Mario is traveling upward as he crosses the barrier.
Re: pass-through bottom sloped tile collision
by on (#137428)
I like to discuss difficult aspects of collision detection, but I must admit I didn't understand the problem very well from the description in the first post. psycopathicteen, could you draw the specific cases you described?
Re: pass-through bottom sloped tile collision
by on (#137442)
Pretty much what Dwedit is showing. In order to avoid that type of glitch requires a lot of extra complications.
Re: pass-through bottom sloped tile collision
by on (#137443)
Edit3: Ah man, I can't read. Seems like what I wrote out is more or less what you described at first. Most of what I can come up with that would be fast fails for platforms above each other (if they're very close.)
Re: pass-through bottom sloped tile collision
by on (#137450)
Well, rainwarrior pretty much mentioned the safest method, check the new and old positions and see if they cross the line (check against the height at that position) and they go downward. The real problem is reliably keeping the player on the slope when on the floor already.

For the record, another common method games do is just check if the player is below the slope line and not going upwards. Yes, this means that you could be going downwards while never going above the line and end up on it. The reason this isn't much of an issue is that normally the area in question is quite small anyway, so at worst it makes jumps more forgiving (which generally is not a bad thing).
Re: pass-through bottom sloped tile collision
by on (#137454)
Being able to do that in SMW I always though was like an advanced technique, not a bug. ;)

Nevertheless, there are simple enough solutions. Forget the "downward" stipulation. Really what you need is already taken care of by "above, then below".

1. Player overlaps slope tile after moving.
2. Player overlaps slope shape after moving.
3. Player start position is above slope line.
4. Player end position is below slope line.

The slope line should be infinite for the purposes of the test. Condition 1 and 2 should confine it to the correct range.

We're still subject to all the usual problems with edges of slopes, here, but that's not specific to being able to jump through them.