How to shoot from a rotating cannon?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ravend

Why does the projectile inherit the rotation of the turret?

enter image description here

main.tscn:

extends Node3D
func _physics_process(delta):
	$Turret.rotate(Vector3.FORWARD, 0.01)

turret.tscn:

extends CSGBox3D
var shell_res: PackedScene = preload("res://shell.tscn")
func _input(event):
	if Input.is_action_pressed("m_left"):
		var shell = shell_res.instantiate()
		shell.apply_central_impulse(global_transform.basis.x)
		add_child(shell)

shell.tscn:

extends RigidBody3D
:bust_in_silhouette: Reply From: jgodfrey

I assume the issue is that you’re adding the instantiated shell as a child of the turret - causing it to inherit properties from the turret.

To fix it, try adding the shells to some container node (for example, a simple Node named shell_container) that’s outside of the turret’s scene structure.