0 votes

Hi, new user starting to get to grips with Godot, having a positioning issue with a child object, I have the following objects setup in the scene like so:
Kinematic2D(Player) > Position2D(PivotPointForGun) > Position2D(Muzzle).

So I instantiate a bullet instance when trigger is fired and it's position is set with these lines:

func shoot():
var b = Bullet.instance()
addchild(b)
b.transform = $PivotPointForGun/Muzzle.global
transform

The PivotPointForGun is just an object setup as a pivot point for the gun sprite to pivot around when rotating - the Muzzle object rotates in correct position and the script works as expected while the Player object is static, but as soon as Player's position moves the position of Muzzle doesn't stay in position relative to it's parent and the bullet instance becomes misaligned with the graphic.

Anyone come across this before, I tried adding a sprite child in the same child/parent relationship for a visual feedback but this rotates and follows its parent as expected so I would expect the bullet to instantiate at the same position.

Thanks.

Godot version 3.3.2
in Engine by (12 points)

your usingb.transform = $PivotPointForGun/Muzzle.global_transform but that its local going to global to do this
b.global_transform.origin = $PivotPointForGun/Muzzle.global_transform.origin

origin is just its x,y,z without anything else

Thanks lewis glasgow, that worked a treat.

Just for completeness and anyone having same issue I also then set the rotation in a similar way:
b.globalrotation = $PivotPointForGun/Muzzle.globalrotation

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.