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?
Pressing left/right rotates the character, while up/down moves it forward or backward in whatever direction it's facing.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With