Appears recordings aren’t allowed so a screenshot will have to do.
Here the enemy capsule isn’t moving and you can see that the turret barrels correctly point at it, but the projeciles are offset. In addition the offset degree seems to be determined either by the turret’s location on the grid, or its location relative to the enemy.
I’ve checked the rotation of all the turret elements and can’t see any anomalies. Also tried instantiating on the barrel rather than the turret top. Behavior is also the same with both basis.z and global_transform.basis.z. Tried an additional line of code to correct the projectile’s rotation upon instantiation:
shot.rotation = turret_top.global_transform.basis.get_euler()
But this achieved nothing. Here are my scripts:
turret.gd:
extends Node3D
@export var projectile: PackedScene
var enemy_path: Path3D
@onready var turret_top: MeshInstance3D = $TurretBase/TurretTop
@onready var turret_barrel: MeshInstance3D = $TurretBase/TurretTop/TurretBarrel
func _physics_process(delta: float) -> void:
var enemy = enemy_path.get_children().back()
look_at(enemy.global_position, Vector3.UP, true)
func _on_timer_timeout() -> void:
var shot = projectile.instantiate()
add_child(shot)
shot.global_position = turret_top.global_position
shot.direction = global_transform.basis.z
TurretManager.gd:
extends Node3D
@export var turret: PackedScene
@export var enemy_path: Path3D
func build_turret(turret_position: Vector3) -> void:
var new_turret = turret.instantiate()
add_child(new_turret)
new_turret.global_position = turret_position
new_turret.enemy_path = enemy_path
projectile.gd:
extends Area3D
var direction := Vector3.FORWARD
@export var projectile_speed := 60.0
func _physics_process(delta: float):
position = position + direction * projectile_speed * delta
func _on_timer_timeout() -> void:
queue_free()
Thanks in advance to whoever points out my oversight. Rotations were my bane back on Unity too.