0 votes

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. :)

in Engine by (15 points)
edited by

1 Answer

+1 vote
Best answer

This is a nasty bug that was discovered in 2.1.3, in which constants from other places of your script could get replaced by others at random.

It was fixed in the upcoming 2.1.4, I tested your script with the beta and it works normally.

by (29,088 points)
selected by

I just tested against all the available binaries at https://downloads.tuxfamily.org/godotengine/ and indeed, my code works with 2.1.4 but none of the previous versions. It also works with 3.0-alpha1 after updating to the new get_ and set_ position methods. I was also just trying to find the bug report at Github without luck. Would you know the issue number for this?

I did a search too, then tried to list all issues I commented in, with no luck either :/

I was hoping to read more about it and figure out how my code triggers the bug and the examples I read don't. I'll look again and comment if I find it but will move forward with 2.1.4 for now. Thanks for your help and insight, Zylann!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.