[2.1.3] Basic movement - Movement in positive x or y requires a Vector2 magnitude 8x that of negative x or y?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ApacheChef
:warning: Old Version Published before Godot 3 was released.

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

:bust_in_silhouette: Reply From: Zylann

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.

I just tested against all the available binaries at Index of /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?

ApacheChef | 2017-08-04 15:18

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

Zylann | 2017-08-04 15:53

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!

ApacheChef | 2017-08-04 18:18