How to handle stairs realistically.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By coder2195

So basically, average blocks are 64x64 pixels
But stairs have steps that are 32x tall
So far, my stairs work out
Player code:

extends KinematicBody2D

var velocity = Vector2.ZERO
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

export var player_speed = 128
export var jump_speed = 25662

func _ready():
	set_position(Vector2(0, -640))

func _physics_process(delta):
	var input_dir = 0
	if Input.is_action_pressed("left"):
		velocity.x += -player_speed * delta
		input_dir = -1
	if Input.is_action_pressed("right"):
		velocity.x += player_speed * delta
		input_dir = 1
	if Input.is_action_pressed("up"):
		if is_on_floor():
			velocity.y = -jump_speed * delta
	velocity.x *= .7
	velocity.y += gravity * delta
	velocity = move_and_slide(velocity, Vector2.UP, true)
	if is_on_wall() && input_dir && is_on_floor():

The last lines handle the stairs.
My stairs are quite successful
This is triggering

Easy way to handle the stairs is using collision polygons

horsecar123 | 2022-03-12 00:31

What you could do is only handle the stairs code if the player is moving into the stairs, Currently your are checking is_on_wall disregarding the fact whether the player is actually trying to move that way or not