How to detect a stairs top in a 2D view?

Well, I show you a video where I’m practicing some animation issues, you can see what I did, but let me explain to you my problem.

I can’t detect the end of the stairs, as you can see, if I keep the up key the character goes up and the going up animation persists, what I want to do is that when the character reaches the top, he suddenly stops.

I marked the “is trigger” on my stairs in order to I could pass through it and I created a variable that tells me when my character is touching the “ground” or not, so, if I touch the stairs and I am touching the “ground”, I can go up, the problem is that at the end, the variable that tells me I’m touching the stairs is active and the variable that tells me I’m touching the “ground” is inactive.

I tried to resolve this with ontriggerenter2D, ontriggerexit2D, oncollisionenter2D or oncollisionexit2D but I can’t.

I was thinking of detecting the height of the object but this seems to me an unpractical method, I don’t know, because imagine that there were a lot of objects to detect and to interact, measuring the dimensions to each one would be awkward.

Can you give me some tips? How this works in 2D games like Metroid, Castlevania and so on?

add another set of trigger boxes floating above each stair step, which the player much be inside of in order to walk up… then omit such boxes at the top?

1 Like

The guide to implementing 2D platformers | Higher-Order Fun You can find there some info about stairs too. It`s really simple.

1 Like

In the games you listed they were almost certainly using a map of tiles.
By examining the map cell beneath (or in front) of the player’s feet they could easily determine if stairs were there. When on stairs they could either handle it as part of general movement or they could have made it a state (AscendingStairs or DescendingStairs). Personally, I’d enter a new state so only the checks applicable to this specific state need to be performed. If AscendingStairs and player reverses direction state changes to DescendingStairs and vice-versa. And so forth.

1 Like

Ohhhh I hadn’t seen that way, thank you guys, I’ll try doing something with the ideas you gave to me.