Can you put all of your code into the codeblock? It is harder to read this way.
ichster | 2020-07-26 18:07
if Input.is_action_just_pressed(“Shoot”):
var pbullet = preload(“res://src/Characters/Pistol_bullet.tscn”).instance()
bullet_container.add_child(pbullet) pbullet.start_at($AnimatedSprite/Pistol.global_rotation,$AnimatedSprite/Pistol/Position2D.global_position)
Because your bullet is set as a child of bullet container, it will inherit transforms of its parent (i.e. bullet_container), which is likely moved by your player.
To fix this, you need your bullet to either be a child of your root get_tree().add_child(pbullet)
seeing as the bullet_container is redundant as you set the position and rotation of it anyway,
or in your ‘Bullet.gd’ script, then add func _ready(): set_as_top_level(true)
and it will inherit the transforms from bullet_container, and your start_at method becomes redundant. This is the method I would recommend.
I tried but none of the solutions work… problem is the ‘y’ co- ordinate of the Position2D also changes when the player flips which logically shouldn’t happen
Make sure the parent(s) of the pbullets have a local transform origin of <0, 0>. Since you are setting the starting local position of the bullets to the global position of the pistol’s bullet spawning position ($AnimatedSprite/Pistol/Position2D), if a parent’s local transform is a bit different than <0, 0>, then that will be perpetuated into the pbullet. If you don’t want to do this, you could try adding the local transform of the parent(s) to the pbullet upon calling start_at: