How do I get the position of an instanced scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mahmoud_Official

if I have a 2 kinematicbody2d’s I want one to have the position of the other body so it can teleport to it, please help.

:bust_in_silhouette: Reply From: exuin

You get the node via its path and then access the position property.

I did, this is what I did:

var instance_object = preload("path of scene")

func _physics_process(delta):
self.position = instance_object.position

it doesn’t work and gives me an error, please help.

Mahmoud_Official | 2021-02-18 15:44

Did you instance the object? What is the error?

exuin | 2021-02-18 15:45

I have a main node containing two players I want to access the player’s position so one can teleport to the other I am having trouble and errors like :

" invalid get index ‘position’ on ‘base packed scene’ ".

Mahmoud_Official | 2021-02-18 19:09

You need to instance the object first.

exuin | 2021-02-18 19:10