Storing the initial local position of an object while taking resizing into account

Hi,
I need to store the initial value of a charachterbody2D object, so I use this :

func _ready() -> void:
	initial_position = position

But if the parent object get moved or resized in any way (even in the editor before running the game), the value doesn’t point to the local initial_point anymore.

Is there a simple way to fix this ?

You need to do some inverse transform matrixing. Although you would be better off using that position and set the node a top_level then just update the position manually. Or use a remote transform node to move it for you and have it ignore scale.

You could get the global_position, that will be the same regardless of changes to the parent. What is this initial_position for?

The problem being that even the global position is not correct, because the parent get moved.
I need this position to get the object to move back to its original location.

What does that means ?

I don’t think these would work, because I would still need to know the original position of the object, but the parent object can be resized and moved.

That’s why I need the local coordinate, so no matter what happen to the parent, these coordinates stay true.

Ok, nevermind, my solution was actually fine, the problem was coming from somewhere else.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.