How to make a function like this from UE4(RotationFromXVector)

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

Here it says what it does

:bust_in_silhouette: Reply From: decepticlown

You don’t need to. Godot uses transform. If you have two nodes A and B and and you want to face A’s forward direction to B then just do:

B.transform.basis.z = A.transform.basis.z

Remember In Godot, Z axis is forward, X axis is right and Y axis is up. More info here :

for example I want to get the forward of velocity (Vector3) and apply it to the player

as I understand from what you said is that I have to only set the z axis of the player to the value of z axis in the velocity


Player.transform.basis.z = velocity.z

ywmaa | 2021-09-24 06:22

I’m sorry for late reply but yes, that should work.

decepticlown | 2021-09-26 11:51

And yes one more thing; there are also global transforms in Godot. So if by chance its not working maybe you need to swap between global to local or vise versa based on your scenario.

decepticlown | 2021-09-26 11:57