Godot Version
<4.2.2 >
Question
Hello everyone,
I’m using an older tutorial to try and make a small 3d shooter sort of like Starfox or or Ex Zodiac.
When it comes to shooting targets, I have Node3D objects attached to my spaceship mesh that stand in as “guns”. They are referenced in the Player class like this:
@onready var guns = [$Gun, $Gun2]
@onready var main = get_tree().current_scene
var Bullet = load("res://bullet.tscn")
and firing them uses a for loop, like this:
if Input.is_action_just_pressed("ui_accept"):
for i in guns:
var bullet = Bullet.instantiate()
main.add_sibling(bullet)
bullet.transform = i.transform
bullet.velocity = bullet.transform.basis.z * -600
The bullets fire from the center of the screen, no matter where I move the spaceship. If I change the “gun” position on the player mesh, the guns get stuck there. I even attached box meshes as children to make sure the Node3D “guns” weren’t just hanging in their initial position and not moving; but it seems like bullets are spawning, ignoring the position of the guns, and moving forward in space. Does anyone have hints to help me spawn the bullet in the right place?
Thank you in advance!