0 votes

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?

asked Nov 14, 2018 in Engine by DarkShroom (52 points)

3 Answers

0 votes
Best answer

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


answered Nov 15, 2018 by DarkShroom (52 points)

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 http://docs.godotengine.org/en/3.0/classes/class_physicsdirectbodystate.html#physicsdirectbodystate.

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.

0 votes

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.

answered Nov 15, 2018 by Kyle Szklenski (14 points)

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.

0 votes

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.add_force(force_dir, force_pos)
    state.add_force(-force_dir, -force_pos)

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

Note: I made this function on the top of my head. I haven't tested it yet so bare with me.

answered Nov 16, 2018 by SIsilicon (3,481 points)
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 How to use this Q&A? before posting your first questions.