How to I apply torque to a rigidbody 3D?

Attention Topic was automatically imported from the old Question2Answer platform.

Many of = the previous functions have gone for adding forces and torque…

currently i can only use:

``````func _integrate_forces(state):
``````

this is fine for normal absolute force

how do i apply torque? or rotational force that rotates an object?

Reply From: Kyle Szklenski

You add torque to a RigidBody, not to the physics state of a RigidBody. There’s a function on RigidBody itself that you can call.

There is no function to add torque on the `RigidBody` itself. The closest would be `set_axis_velocity`, but it may not be the most convenient.

Zylann | 2018-11-15 18:58

someone on the godot facebook group has confirmed it is coming for version 3.1

closed!

Strange, I was able to use torque in 3.0, it’s not missing^^
I implemented `_integrate_forces` and used the `PhysicsDirectBodyState` argument, it has a function to apply torque PhysicsDirectBodyState — Godot Engine (3.0) documentation in English.

If you need to apply torque from outside, you could make a variable that you set outside, and apply it when `_integrate_forces` gets called.

Zylann | 2018-11-15 18:56

You know if there is no function to add torque, maybe you could emulate it.

``````func add_torque(state, torque_axis):
var force_pos = torque_axis.cross(Vector3(0,1,0)).normalized()
var torque = torque_axis.length()
var force_dir = force_pos.cross(torque_axis).normalized() * torque

`state` is, well `state`. The direction of `torque_axis` is the axis your adding torque about. Its length defines the strength of the torque.