Topic was automatically imported from the old Question2Answer platform.
Asked By
bgegg
i want get character position.
i add this code for the it.
extends Camera2D
var character_pos
var camera_pos
func _ready():
var character_path =get_node("../character")
character_pos = character_path.get_transform()
print(character_pos)
but transform is index z of inspector tab.
i get this resulut by “print(character_pos)”.
and i get this error code when use "print(character_pos.z) ".
invaild get index “z”
how to get transform position in inspecter tab for 2d?
Transform in 2D contain only Vector2(x,y). You cannot get z over it.
To get your sprite position you can use in your script:
character_pos = character.position
or
character_pos = character.get(“position”)
In case if you use get_transform method in 2d you get Transform2D class
which contain 3 Vector2 values:
Which are :
Vector2 x , Vector2 y and Vector2 origin.
This is what you get when you print.
thanks for comment.
i can get position 2d by your code.
var character_path =get_node("../character")
character_pos = character_path.position
but why do not come out intelisense of position after the character_path.?
bgegg | 2019-05-30 12:02
I not got your last question. what means word “intelisense” ?
you can get also like this
var character_pos = get_node(“…/character”).position