So for more than a month now I have been trying to get this right and now I have the right Code for staits to work.
func _process(delta)
if Input.is_action_pressed(“ui_left”):
position.y+= delta * 100
if Input.is_action_pressed(“ui_right”):
position.y-= delta * 100
the problem is I have no idea how to make this work in the area2d.
I add the _on_area2d_body_entered signal but then I cant use _process(delta). does anyone have an idea?
and btw this is the code for character movement: @export var speed: int = 100
var direction=Vector2.ZERO
func handlInput():
direction=Input.get_vector(“ui_left”,“ui_right”,“ui_up”,“ui_down”)
velocity = direction*speed
You could have an var on_stairs = false variable, and use _on_area2d_body_entered to set it to true and _on_area2d_body_exited to set it to false, so you’d know when the character is using stairs.
Then in the movement code:
if on_stairs:
if direction < 0:
position.y+= delta * 100
elif 0 < direction:
position.y-= delta * 100
Or I guess setting velocity.y instead of position.y might be better.
I have just started working with godot… can you write in code mate?
var on_stairs = false
func _process(delta):
if on_stairs:
if Input.is_action_pressed(“ui_left”):
velocity.y+=delta * 100
elif Input.is_action_pressed(“ui_right”):
velocity.y-= delta * 100
func _on_peleh_body_entered(body):
on_stairs=true
I did this and still nothing. the direction code you used made the game crash on the click of start so I still use Input.is_action_pressed(“ui_left”) instead
still nothing… the character goes in the area2d but nothing happens. I have connceted the body_entered signal to the player script and made the on_stairs True there but nothing.
extends CharacterBody2D
@export var speed: int = 100
var on_stairs = false
var direction=Vector2.ZERO
func handlInput(delta):
direction=Input.get_vector("ui_left","ui_right","ui_up","ui_down")
velocity = direction*speed
if on_stairs==true:
if direction.x < 0:
velocity.y+=delta * 100
elif direction.x > 0:
velocity.y-= delta * 100
func _physics_process(delta):
handlInput(delta)
move_and_slide()
func _on_peleh_body_entered(body):
on_stairs=true
fyi the _on_peleh_body_entered is the area2d signal