I’m trying to simulate the growth of a tree. The branches can grow at various angles, but I want the leaves to always face up, towards the light. If I understand 3d transforms correctly, all I need to do is to align the object’s basis to global XYZ axes, so I put something like this in the _ready function:
Hi! It looks to me the leaves are facing up each branch instead of the stem. Either the code snippet did its job and the new orientation got applied, then just orient them upwards relative to the stem instead of each branch. If the code did not do its job something might have gone wrong along the way.
A common pitfall to me is that each node needs to be added to the scene tree first before using (getting and setting) the global orientation.
func _ready() → void: var normal_vector = to_global(basis.y.normalized()) var up = Vector3.UP var axis = normal_vector.cross(up) var angle = normal_vector.signed_angle_to(up, axis) global_rotate(axis, angle)
There was, it wanted me to normalize the calculated axis. Fixing that didn’t really change much unfortunately. I think there is some rotation now, but nowhere near what I expect there to be.
I got it to work. I used the same code as I posted in the original question, but instead of the leaf’s _ready function I created a function in the script for the parent scene and called it there. Makes me REALLY question what ‘global’ actually means. When I created a separate function in the script for leaf and called it in the script for the parent scene it didn’t work either. ¯\_(ツ)_/¯