how to get transform position in 2d?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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)”.
enter image description here

and i get this error code when use "print(character_pos.z) ".
invaild get index “z”
enter image description here

how to get transform position in inspecter tab for 2d?

:bust_in_silhouette: Reply From: extcFPjkCLsDC2F

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

extcFPjkCLsDC2F | 2019-05-31 07:31

sorry
intelisense meant auto complete

bgegg | 2019-05-31 07:53