This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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

Godot version v. 3.3.2
in Engine by (46 points)

1 Answer

+2 votes

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

by (2,260 points)

Still not working, but thanks anyway

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.