Inverse kinematics combined with active ragdoll physics help.

Godot Version

v4.6- dev6 win64

Question

I am trying to create a system where I have one rig (PhysicalBone3D) Trying to copy the bone poses of another rig (IK) using linear and angular velocity.

Here’s the problem: When running the game the physics bones seem to move to the rest position of the skeleton.

While it should try and follow the IK rig.

This is the IK rig for reference.

This is strange because I tested if the physics rig would move to a rig that uses an animation player it does work.

I hope someone can help!

Additional information

Picture of the physics legs scene tree

Picture of the IK legs scene tree

extends PhysicalBoneSimulator3D

@export var Target_Skeleton:Skeleton3D

var current_delta:float


func _ready() -> void:
	active = true
	physical_bones_start_simulation()
	get_parent().skeleton_updated.connect(update)


func _physics_process(delta: float) -> void:
	current_delta = delta


func update() -> void:
	for bone:PhysicalBone3D in get_children():
		var target_transform:Transform3D = Target_Skeleton.global_transform * Target_Skeleton.get_bone_global_pose(bone.get_bone_id())
		var current_transform:Transform3D = get_parent().global_transform * get_parent().get_bone_global_pose(bone.get_bone_id())
		var position_difference:Vector3 = target_transform.origin - current_transform.origin
		var force = hookes_law(position_difference, bone.linear_velocity, 3000.0, 80.0)
		
		bone.linear_velocity += force * current_delta
		
		var rotation_difference: Basis = target_transform.basis * current_transform.basis.inverse()
		var torque = hookes_law(rotation_difference.get_euler(), bone.angular_velocity, 3000.0, 80.0)
		
		bone.angular_velocity += torque * current_delta


func hookes_law(displacement:Vector3, current_vel:Vector3, stiffness:float, damping) -> Vector3:
	return (stiffness * displacement) - (damping * current_vel)

The code used to move the physics bones

If more information is needed please tell me and I will happily provide it!

Have a great day :slight_smile: