Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ravend |
how to rotate the added scene in the direction of the parent?
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()
get_tree().get_root().add_child(shell)
#var rot = Vector3()
#rot.x = acos(global_transform.basis.x.dot(shell.transform.basis.x))
#shell.global_rotate(Vector3.LEFT, rot.x)
#rot.y = acos(global_transform.basis.y.dot(shell.transform.basis.y))
#shell.global_rotate(Vector3.UP, rot.y)
#rot.z = acos(global_transform.basis.z.dot(shell.transform.basis.z))
#shell.global_rotate(Vector3.FORWARD, rot.z)
shell.apply_central_impulse(global_transform.basis.x)
shell.tscn:
extends RigidBody3D
if not rotated, the child scene inherits the root vector:
if you uncomment the calculations, I get the wrong effect:
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