Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Godot 3d get Forward Vector

Tags:

vector

3d

godot

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?

like image 937
SanzioSan Avatar asked Jan 25 '18 08:01

SanzioSan


People also ask

How do you move forward in Godot?

Pressing left/right rotates the character, while up/down moves it forward or backward in whatever direction it's facing.

Which direction is forward in Godot?

Note that Unity's forward direction is the position Z-axis while Godot's forward direction is the negative Z-axis. The back directions are also inverted.

How do you rotate a vector in Godot?

Rotating a 2D vector 90° degrees to either side, left or right, is really easy, just swap x and y, then negate either x or y (direction of rotation depends on which is negated).


1 Answers

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.

like image 198
Daniklad Avatar answered Oct 05 '22 02:10

Daniklad