Can I change rotation of a bone with code? How to get the bone?
How to control Bones with Code in Godot 4 Beta
- Edited
- Best Answerset by Container
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