How to add torque to physical bones?

Godot Version

4

Question

Hi, I'm making a ragdoll character, and I want to know how to add torque to my bones in order make them spin and to keep my character upright, mostly to keep my ragdoll character up right. I know you can't just add torque to physical bones so I'm a bit lost on what to do

You can apply torque to any object that implements the _integrate_forces() method. In case you don’t know, this method is similar to _physics_process() (but not identical). It provides a state-parameter of type PhysicsDirectBodyState3D which you can use to directly modify the physics state of the object.

func _integrate_forces(state):
	var torque = Vector3.ONE
	state.apply_torque(torque)

So, while PhysicsBone3D doesn’t directly provide an interface to apply torque to the object, torque is still easily applied via the use of _integrate_forces().


Let me know if you have any other questions.

1 Like

I knew about this but didn’t think it would work with physical bones. Does applying force using this work just like applying force to a rigid body or physical bone? Also how do I apply_torque to a physical bone3D from a parents script

In order to do that, you would have to make a script that inherits from PhysicsBone3D and implements a system capable of receiving and handling torque requests. For example:

class_name MyPhysicsBone3D
extends PhysicsBone3D

var torque_requests: Array[Vector3]

func _integrate_forces(state):
	# Apply all torque requests
	for t in torque_requests:
		state.apply_torque(t)

	# Clear the torque requests
	torque_requests.clear()

# Function called by parent script
func apply_torque(torque: Vector3):
	torque_requests.append(torque)

I’m not sure about the execution order of _integrate_forces() and _physics_process(). It’s possible that the torque requests will be applied one physics frame later. You will have to test if that becomes an issue.

1 Like

Say I wanted to make a func that could set the Vector3 for the torque when its called, how would I do that? its something like physicalbone3d.the_func(Vector3(1, 0, 0) right? and then the func on the other side has the_func(torque_setting) right?

Your use of terminology is quite loose. I think I understand what you’re saying though.

Is there something about my example in my previous post that you do not understand or that somehow doesn’t apply to you?

Hmmm, I think your example already explained this and I didn’t notice. So never mind I’m all good now

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.