- Edited
Glossing over details can be extremely frustrating to new learners, like myself, while following along with stuff like this. I'm only this far into the documentation and I'm really hoping this doesn't happen a lot.
https://docs.godotengine.org/en/stable/getting_started/step_by_step/scripting_player_input.html
On the page linked above, it says the following:
For turning, we should use a new variable: direction. Update the top of the _process() function like so, up to the line where we increment the sprite's rotation.
func _process(delta):
var direction = 0
if Input.is_action_pressed("ui_left"):
direction = -1
if Input.is_action_pressed("ui_right"):
direction = 1
rotation += angular_speed * direction * delta
However, those instructions result in the following code, which you quickly learn is a problem.
extends Sprite
var speed = 400
var angular_speed = PI
func _process(delta):
var direction = 0
if Input.is_action_pressed("ui_left"):
direction = -1
if Input.is_action_pressed("ui_right"):
direction = 1
rotation += angular_speed * direction * delta
var velocity = Vector2.UP.rotated(rotation) * speed
position += velocity * delta
If you're going to specify only updating the top of the function instead of all of it, there should be a reason you're saying it. And this next part is nitpicky, but technically (because of how English works), the final code looks like this while following along (which still works, sorta, but is also wrong):
Replace the line starting with var velocity with the code below.
extends Sprite
var speed = 400
var angular_speed = PI
func _process(delta):
var direction = 0
if Input.is_action_pressed("ui_left"):
direction = -1
if Input.is_action_pressed("ui_right"):
direction = 1
rotation += angular_speed * direction * delta
var velocity = Vector2.ZERO
if Input.is_action_pressed("ui_up"):
velocity = Vector2.UP.rotated(rotation) * speed
position += velocity * delta
position += velocity * delta
I think quality tutorials are really important, and kinda rare. It's easy to make assumptions when you understand the material, which is never the user. I'll be pointing out issues as I find them, but I'm not sure if this is the best place to identify them.