How to Use Correctly the Position2D Node?? [SHOOT PROJECTILES]

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

I’ve created a Area2D node called “Bullet”, and when i press the “Z” button, that node is called right into the Main Scene, and that was working really well.

The problem is, i want to set the Bullet position equals to my Position2D Node position (which belongs to the player node), and for some reason i don’t know, that code i wrote doesn’t work, what have i done wrong? Thanks is advance.

#Shoot Function
if Input.is_action_just_pressed(“Shoot”):
var bullet = bPath.instance()
bullet.position = $Position2D.global_position
get_tree().current_scene.add_child(bullet)

Here’s the Node hierachy:
Player
|----AnimatedSprite
|----CollisionShape
|----Camera2D
|----Position2D

Bullet
|----AnimatedSprite
|----CollisionShape

:bust_in_silhouette: Reply From: estebanmolca

Try this: bullet.position = $Position2D.position
It is the position with respect to the parent (Player).

Still not working, but thanks anyway

Matt101 | 2021-08-18 16:39

Perhaps the problem is in the Position2D node, cause when i use the Player’s own position it works, like that:

bullet.position = position

But still, that’s not what i want to do

Matt101 | 2021-08-18 16:41