Position of a node

Whenever I try to get position of a node using

$Node.position

or

$Node.global_position

it always returns (0,0)

how do i fix this?

what “actual” position does it have?

basically i’m trying to find direction in which player moves, so I was trying to find position of a player in one frame, and then subtract it from position in next frame. not sure what the actual position would be

Can you show the code thats supposed to do this?

func _physics_process(delta: float) -> void:
	
	var last_frame_position = global_position
	var direction = global_position - last_frame_position

Lets say global_position = (12,24)
var last_frame_position = global_position
This line makes last_frame position = (12,24)
var direction = global_position - last_frame_position
This line makes direction = (0,0)
global_position(12,24) - last_frame_position(12,24)

A nodes global_position does not change within the function. Whatever it was at the beginning of the function is what it will be on the last line of the function.

Store last_frame_position outside of the function at class level

var last_frame_position:Vector2
# you will probably need to initialize it so it doesn't start at (0,0) 
func _ready()->void: 
   last_frame_position = global_position
func _physics_process(delta: float) -> void:
	var direction = global_position - last_frame_position
    last_frame_position = global_position

right, how do I find change in position then?

If you read sancho2’s last response, you’ll find the exact code you need to find the change in position.

The big difference between your code and his code is that your code will ALWAYS result in no change because your code is calculating the difference between the current position and the current position, which will always be zero.