0 votes

I have a simple testing script which allows me to move a node around based on different inputs from my keyboard which I can change per node (think WASD and IJKL). Ever since I updated to 3.3 I've been getting an error. Sometimes I'll make changes to a script like this that inherits from Node, and all of a sudden I'll get an error:

"The identifier global_position isn't declared in the current scope"

Now this same script had been working before, so I'm not sure if I changed something I'm not aware of. Here's my code:

extends Node

export var speed : float = 1
export(String, "Motor 1", "Motor 2") var motor = "Motor 1"

func _process(delta):
var movedirection
if motor == "Motor 1":
    movedirection = testdir.direction_from_input_test1()
elif motor == "Motor 2":
    movedirection = testdir.direction_from_input_test2()

global_position = global_position + (movedirection * speed)

Does anyone have any ideas? I'm guessing I'm misunderstanding the intended use of something. Thanks very much for your time.

Edit: I should mention closing and re-opening the editor doesn't fix it.

Godot version 3.3
in Engine by (34 points)

1 Answer

0 votes
Best answer
extends Node

Node objects don't have a global_position. Your object needs to inherit from a Node2D object (or lower) to have a global_position.

by (3,707 points)
selected by

Oops. Thank you for taking the time to respond. I appreciate it.

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 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 webmaster@godotengine.org with your username.