How to synchronize vectors?

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

how to rotate the added scene in the direction of the parent?


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


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()

    	#var rot = Vector3()
    	#rot.x = acos(
    	#shell.global_rotate(Vector3.LEFT, rot.x)
    	#rot.y = acos(
   		#shell.global_rotate(Vector3.UP, rot.y)
    	#rot.z = acos(
    	#shell.global_rotate(Vector3.FORWARD, rot.z)



extends RigidBody3D

if not rotated, the child scene inherits the root vector:

if you uncomment the calculations, I get the wrong effect:
enter image description here

how to correctly synchronize the scene vectors?

Are you just trying to set each shell’s initial orientation to that of the turret at the time it’s instantiated or are you trying to keep each shell’s orientation synched with the turret over time as it’s rotated?

jgodfrey | 2023-03-03 14:42

I set the initial trajectory. later shell and turret are independent.

ravend | 2023-03-03 15:05

:bust_in_silhouette: Reply From: fuck

An easy way to make a node point in the direction of a given vector is with Node3d.look_at()

so you could use:
shell.look_at(shell.position-global_transform.basis.z) or something like that
By convention “forward” is the negative z axis, but you can adjust it to be whichever local axis the turret points towards.