I'm obviously missing something basic here but Googling and looking at other basic movement code isn't answering my question.
I've a very basic scene as I'm new to Godot. There's a Node2D with a Label child and the label is positioned roughly in the center of the view. The Node2D has the following script attached:
extends Node2D
var labelObject
var direction = Vector2(0,-1)
var speed = 10
func _ready():
labelObject = get_node("Label")
set_process(true)
func _process(delta):
var labelPos = labelObject.get_pos()
labelPos += speed * direction * delta
labelObject.set_pos(labelPos)
labelObject.set_text(str(labelPos))
When you run this it works as you'd expect: The label drifts up toward the top of the game window updating the label text as it goes. However, when changing the direction vector to
var direction = Vector2(0,1)
and running the scene, the label just sits there in the same position updating its text. The interesting thing is that the decimal part of the y component bounces around .1333, give or take a few hundredths, which is about the value that the Godot editor tells me for delta
when pausing the mouse cursor over it. It's like the value is being clamped.
In order to get the label to move in positive y, down the game window, I have to either change direction to var direction = Vector2(0,8)
or change speed to var speed = 80
to get what appears to be the same visual motion.
The same issue applies to x.
All the other code I've looked at using the same approach, speed multiplied by a direction vector multiplied by delta, uses 1 or -1 for their vector components.
So yeah, I'm stumped and feeling like I'm missing something simple. :)