Skip to content

Instantly share code, notes, and snippets.

@and3rson
Created January 21, 2019 00:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save and3rson/b339842fb53495a3bbc295210683d934 to your computer and use it in GitHub Desktop.
Save and3rson/b339842fb53495a3bbc295210683d934 to your computer and use it in GitHub Desktop.
Simple ragdoll physical bones creation plugin for Godot
tool
extends EditorPlugin
var button : Button
func _enter_tree():
print('physbones: plugin created')
button = Button.new()
button.text = 'CPB'
button.connect('pressed', self, 'create_physical_bones')
self.add_control_to_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, button)
func _exit_tree():
print('physbones: plugin destroyed')
self.remove_control_from_container(EditorPlugin.CONTAINER_SPATIAL_EDITOR_MENU, button)
button.queue_free()
func create_physical_bones():
var node : Skeleton = self.get_editor_interface().get_selection().get_selected_nodes().front()
self.get_editor_interface()
if not (node is Skeleton):
print('physbones: must select skeleton')
return
for bone_id in range(node.get_bone_count()):
var bone_name = node.get_bone_name(bone_id)
var pbone = PhysicalBone.new()
node.add_child(pbone)
pbone.set_owner(get_editor_interface().get_edited_scene_root())
pbone.name = 'PB ' + bone_name
var global_pose : Transform = node.get_bone_global_pose(bone_id)
pbone.global_transform = global_pose
pbone.bone_name = bone_name
var collision = CollisionShape.new()
collision.shape = CapsuleShape.new()
(collision.shape as CapsuleShape).radius = 0.025
(collision.shape as CapsuleShape).height = 0.2
collision.transform = collision.transform.rotated(Vector3.UP, PI / 2)
collision.transform = collision.transform.translated(Vector3(0, 0, 0.1))
pbone.add_child(collision)
collision.set_owner(get_editor_interface().get_edited_scene_root())
print('physbones: done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment