Make Physical Skeleton in code?

Godot Version

4.3

Question

Basic question , is there a way to Create Physical Skeleton in code ? I like it all , but I want to make it automatic in the func _ready() or when the skeleton enters the tree.

You can do var skeleton: Skeleton3D = Skeleton3D.new(), but you’d have to populate it with data in code as well…

yea your right , I want all the stuff that " Create Phyisical Skeleton 3d " button does automatically , I want the simulator3D as the next child , and that child being every physical bone and another child to that being the Colission shape . . I also want the position shapes .


ALl of this is created by hitting that button in the Skeleton tab , but I feel like there should be a code way to execute it as well . If it doesnt Exist I will make one. Here is what I have so far

func _ready() → void:

var skel_root : PhysicalBoneSimulator3D = PhysicalBoneSimulator3D.new()

add_child(skel_root)

for i in self.get_bone_count():
	var one_physical_bone :PhysicalBone3D = PhysicalBone3D.new()
	skel_root.add_child(one_physical_bone)
	var name = self.get_bone_name(i)
	one_physical_bone.bone_name = name
	
#skel_root.physical_bones_start_simulation()

ok well if anybody needs a function that about does the same here it is
func skeleton_on_fly():

var skel_root : PhysicalBoneSimulator3D = PhysicalBoneSimulator3D.new()

add_child(skel_root)

for i in self.get_bone_count():
	var one_physical_bone :PhysicalBone3D = PhysicalBone3D.new()
	
	skel_root.add_child(one_physical_bone)
	

	var name = self.get_bone_name(i)
	one_physical_bone.bone_name = name
	var rest_bone :Transform3D = self.get_bone_global_rest(i)
	one_physical_bone.transform = rest_bone
	
	var capsule_mesh :CapsuleShape3D = CapsuleShape3D.new()
	capsule_mesh.height = .2
	capsule_mesh.radius = .2
	var colission_shape :CollisionShape3D = CollisionShape3D.new()
	colission_shape.shape = capsule_mesh
	one_physical_bone.add_child(colission_shape)
	one_physical_bone.set_joint_type(1)
skel_root.physical_bones_start_simulation()
1 Like

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