Top Down Stairs That Face South

Godot Version

Godot 4


Has anybody ever made proper south facing stairs in a topdown 2D game?
I got it working somewhat, just that im unable to turn around to exit while already within the stair, the player has to walk all the way down and then climb back up.
The way i set it up: the tile itself has 2 collision layers, both guard the player from going below or above the stair,
on top of the tile i put the scene of a stair with 2 area2Ds that does the following:
once the player steps on the bottom area 2d his y input is inverted
once player reaches top, his y inversion stops and collision layers are updated
similar setup for the way down.
it works until i want the player to move back out of the stair after his y input is inverted.
I dont think the way i set it up can be improved any further without changing the whole thing over, so Im asking if anyone else has got these kinds of stairs to work? how did you do it?
extends Node2D

func _on_top_body_exited(body):
if body.is_in_group(“persons”):
if body.is_on_stair_s_top and body.global_position.y < $Bottom.global_position.y and body.collision_layer==1: # exit from top
body.is_on_stair_s_top = false
elif !body.is_on_stair_s_top and body.global_position.y < $Bottom.global_position.y and body.collision_layer==2:
body.is_on_stair_s_top = true

func _on_bottom_body_entered(body):
if body.is_in_group(“persons”):
if !body.is_on_stair_s_top and body.global_position.y < $Bottom.global_position.y and body.collision_layer==1: # enter from top
body.is_on_stair_s_top = true
if body.is_on_stair_s_top and body.global_position.y < $Bottom.global_position.y and body.collision_layer==2:
body.is_on_stair_s_top = false

code for the stairs: