Godot Version
4.7
Question
so i’m just trying to write some basic grid based movement code, yet my node doesn’t seem to move. (script extends animation player which parents the sprite2d)
move_down(event) -> void:
if event.is_action_pressed("ui_down"):
var hold_var = float($Sprite2D.position.y+32)
print(hold_var)
$Sprite2D.position = Vector2($Sprite2D.position.x, hold_var)
You need to use the input function:
~~~
func _input(event: InputEvent) -> void:
if event.is_action_pressed("jump"):
print("The player jumped!")
but if the name is part of the function’s method, how do you actually name a function or get different functions to do similar but different things?
Some functions are “virtual” meaning you can override them and they will be called automatically at certain times. Such as _ready will be called when the node is first added to the scene, _process will be called every frame. Other functions that do not share a virtual name and arguments are not overrides, and must be called manually.
Generally you get input in one place anyway:
~~~
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_up"):
move_up()
elif event.is_action_pressed("ui_down"):
move_down()
~~~
You can also check for a keypress in the _process function. You probably want to study the manual and decide which way you want to go with it.