Godot Version
most recent
Question
Hi
I have a problem with a turret, which is a child node of a ship. I can fire from it and the bullets will go along the negative z-axis and also kind of up or down depending on in which direction the ship is facing. They wont at all go left or right though. I messed around a bit with combing various values but cant find a good solution. Reverted to just shooting straight.
Does anyone have any ideas?
extends Marker3D
const BULLET_SCENE = preload(“res://BULLET_TEST.tscn”)
func _process(delta):
if Input.is_action_just_pressed(“ui_accept”):
spawn_bullet()
func spawn_bullet():
var bullet_instance = BULLET_SCENE.instantiate()
# Set the bullet's global transform to match the turret's (spawn position)
bullet_instance.global_transform = self.global_transform
# Access the ship's global transform (the ship is the parent of the turret)
var ship = get_parent()
if ship:
var forward_direction = -ship.global_transform.basis.z
bullet_instance.direction = forward_direction
var bullets_parent = get_node("../../Bullets")
if bullets_parent:
bullets_parent.add_child(bullet_instance)