• Godot Help
  • How to control Bones with Code in Godot 4 Beta

Can I change rotation of a bone with code? How to get the bone?

  • Hello, I had a quick test and this is how I did it.

    I attached this code to my Skeleton Node:

    extends Skeleton3D
    
    
    func _physics_process(delta):
    	var t = get_bone_pose_rotation(1)
    	if Input.is_action_pressed("ui_up"):
    		t = t.slerp(Quaternion(Vector3(200, 0, 0)), 0.1)
    		set_bone_pose_rotation(1,t )
    
    	if Input.is_action_pressed("ui_down"):
    		t = t.slerp(Quaternion(Vector3(-200, 0, 0)), 0.1)
    		set_bone_pose_rotation(1,t )

    Using Up, Down arrow to rotate the bone

    *Please ignore my messy mesh, I didn't loopcut it properly.

    Basically the (1) here is the bone ID.

    var t = get_bone_pose_rotation(1)


    Then rotate axis x by 200,-200 using slerp.

    t = t.slerp(Quaternion(Vector3(200, 0, 0)), 0.1)

    I don't know much about Quaternion(). I just used it because Godot kept telling me to LOL.

Hello, I had a quick test and this is how I did it.

I attached this code to my Skeleton Node:

extends Skeleton3D


func _physics_process(delta):
	var t = get_bone_pose_rotation(1)
	if Input.is_action_pressed("ui_up"):
		t = t.slerp(Quaternion(Vector3(200, 0, 0)), 0.1)
		set_bone_pose_rotation(1,t )

	if Input.is_action_pressed("ui_down"):
		t = t.slerp(Quaternion(Vector3(-200, 0, 0)), 0.1)
		set_bone_pose_rotation(1,t )

Using Up, Down arrow to rotate the bone

*Please ignore my messy mesh, I didn't loopcut it properly.

Basically the (1) here is the bone ID.

var t = get_bone_pose_rotation(1)


Then rotate axis x by 200,-200 using slerp.

t = t.slerp(Quaternion(Vector3(200, 0, 0)), 0.1)

I don't know much about Quaternion(). I just used it because Godot kept telling me to LOL.

    11 days later

    Gowydot Is it possible to display the bone id in the inspector (I have many bones and I dont want to count them all)

      Container
      You can use find_bone("bone_name")

      var a = find_bone("Bone.001")
      
      func _physics_process(delta):
      	var t = get_bone_pose_rotation(a)
      	if Input.is_action_pressed("ui_up"):
      		t = t.slerp(Quaternion(Vector3(200, 0, 0)), 0.1)
      		set_bone_pose_rotation(a,t )