Godot 3d get Forward Vector

SanzioSan picture SanzioSan · Jan 25, 2018 · Viewed 7.7k times · Source

I was wondering if there was a way to get the forward vector of a spatial node in godot 3d.

In unity this would simply be transform.forward.

Godot gives me a rotational vector but im not sure how to convert this to a directional vector.

What is godot's version of transform.forward?

Answer

Daniklad picture Daniklad · Oct 9, 2019

Forward is what you decide it should be. I usually do this:

var aim = $Player.get_global_transform().basis
var forward = -aim.z
var backward = aim.z
var left = -aim.x
var right = aim.x

Of course it helps if you have a convention for this when designing your assets and scenes. I always use -Z as forward but you can choose differently if you so wish.