![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | eurospin |
Hello guys. It’s my first time writing on this forum. I recently discovered Godot and i’m following a tutorial to learn basic things. I have some several problems. This is my code:
extends Sprite
func _ready():
pass
func _process(delta):
var velocity = Vector2()
if Input.is_key_pressed(KEY_UP):
velocity.y = -5
if Input.is_key_pressed(KEY_DOWN):
velocity.y = 5
if Input.is_key_pressed(KEY_LEFT):
velocity.x = -5
if Input.is_key_pressed(KEY_RIGHT):
velocity.x = 5
self.position = self.position + velocity.normalized()*5*delta
And the sprite moves only if i press down+right, it will move diagonally . And then i can move the sprite also in down direction. If i write this code:
func _process(_delta):
var velocita = Vector2()
var deltaFrame = _delta * 60
if Input.is_key_pressed(KEY_W):
velocita.y = -1
if Input.is_key_pressed(KEY_S):
velocita.y = 1
if Input.is_key_pressed(KEY_A):
velocita.x = -1
if Input.is_key_pressed(KEY_D):
velocita.x = 1
self.position += velocita * 5 * deltaFrame
The sprite moves correctly . But i’d like to use arrow keys on the keyboard. Also this code managed to solve the errors I will explain down low.
Another problem is this:
Any code I copy or write I always get errors like “misplaced func” or “expected intended block” or “identifier input isn’t declared in this scope”. There are no grammatical errors. I tried to copy the code point by point both as written by Crystal Bit and by LordXenon. It’s frustrating because I can’t go on with the tutorial and anything I do always gives me error. I also tried various combinations of tabs, spaces and enter but nothing changes. I specify that I am using the latest version of Godot 3.2.1
PS: I tried again to copy the code written by Crystal Bit, and I found that if I press enter, between “func _ready” and “func _process”, it returns an “expected intended block” error, if I press tab on “func _process” it returns an “misplaced func” error . I solved it by using the word “PASS” under “func _ready” and pressing tab. While as regards the syntax, if I write “func _process (delta):” it returns me wrong, forcing me to write “(_delta):” or “(_event):” or “(_process)” for example, all of these with the underscore before the word.
Now I don’t know if this procedure is a bit forced or something has actually changed in the new versions of Godot. If anyone can enlighten me, it would do me a great favor.