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.
Hi, I know that this is pretty old now, but I am trying to do the same in 4.4.1, but get the following error on the line:
bone_pose = bone_pose.slerp(Quaternion(Vector3(200, 0, 0)), 0.1)
Parser Error: No constructor of "Quaternion" matches the signature "Quaternion(Vector3)".
Any thoughts?
Cheers,
patey
It no longer just take one (Vector3) parameter I guess. Maybe use this Quaternion(axis: Vector3, angle: float) instead.
https://docs.godotengine.org/en/stable/classes/class_quaternion.html#constructor-descriptions