This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

In Godot is it possible to apply force or set the velocity of a rigidbody or a kinematicbody on local axis? If so, how can you do it? Thank you for your time.

in Engine by (136 points)
edited by

1 Answer

+2 votes
Best answer

You need to use the transform of the rigidbody to convert the local axis to a global axis:

var forcemult=20
var direction= Vector3(0,0,-1) #example: direction in -z
var global_direction = global_transform.basis.xform(relOffset)
apply_impulse(Vector3(0,0,0), global_direction * forcemult) #apply to bodies center

I used global_transform because this also directly transforms the axis when the body is child of another body.
If you want to transform a global value back to a local then use global_transform.basis.xform_inv(vector)

(Doesn't have to be a RigidBody, any Object derived from Spatial has a transform)

by (3,370 points)
selected by

Thanks for the great answer. It worked!

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.