+3 votes

I want a rigidbody to move forward along its own local axis, so when it rotates, it will still go forward from its own point of view. But this should be done using physics, via apply_impulse.

in Engine by (35 points)

1 Answer

0 votes

Although physics are executed in world space, you can get the forward vector of a spatial node like this:

var forward = -get_transform().basis.z

Or, if you are unsure:

var forward = -get_global_transform().basis.z

Then you can use it to apply a force.

Note: I wrote a - in front of the Z axis, because the engine uses the OpenGL axis convention, so for example a camera looks at -Z instead of +Z, just FYI

by (28,982 points)
edited by

Thanks a lot

What about 2D? transform2d doesn't have basis.

Transform2D is also a mix of basis and translation. You have the up and right vectors right away, with transform2d.x and transform2d.y.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.