I'm new to Godot and have based some code on a video that shows an arrow being fired:
The part of the video where they create the arrow:
They update the arrow with
However, I want it to have proper phsyics, so I use
export (PackedScene) var arrow_template
var shoot_speed = 10
var arrow = arrow_template.instance()
var arrow_spawner_position_node = get_node("Position2D")
# Get the position of the arrow when it's a child of our Position2D
# node, store it, remove the arrow from it, and reapply it when it's
# a child of the scene.
# var global_pos = self.global_position
# arrow_spawner_position_node.global_position = global_pos
var distance = owner.get_global_mouse_position() - self.global_position
arrow.apply_impulse(Vector2(), distance * shoot_speed)
This mostly works, except that moving the mouse (which causes
look_at() to be called) affects the arrow:
I figure this is probably because the arrows are being created as children of the spawner, which itself is a child node of the player. So I tried fixing it - see the commented-out code above, where I've also explained what I was trying to do. My attempt failed though...
Here's what my node/scene trees look like:
So: what is the correct way to spawn an arrow that takes the initial position and rotation of the shooter without being affected by it after it's been shot?