I’ve written a simple game engine program where this snake follows the cube. I’ve set the bones of the snake to rotate by tracking the position of the cube. However, I’d like to scale the rotation of the other bone by, say, a half. Could someone direct me in the right direction? I understand this will probably mean that I have to create some kind of vector value, then convert it to a quaternion and multiply it? This would all need to be done in Python.
I don’t think you can do this with scalar multiplication on a quaternion. I think you need 2 tracking quaternions:
The quaternion you already have that gives you a full rotation
A quaternion that represents “no rotation” of your bone.
Once you have the two quaternions, just do a weighted average for each of the components and then normalize the final result. Note, that approach has pros and cons. Try searching for “slerp” and “lerp” or “nlerp” for more info about “spherical linear interpolation”.
# Note this is pseudo code and I have not tested it.
# Assumes 'fullRotationQuat' is the quaternion for the full rotation and 'noRotationQuat' is a quaternion for no rotation on your bone.
# 'weight' should be between [0, 1.0] and indicates how close to the final rotation you want to be. 1.0 = full rotation.
finalQuat.w = weight * fullRotationQuat.w + (1.0 - weight) * noRotationQuat.w
finalQuat.x = weight * fullRotationQuat.x + (1.0 - weight) * noRotationQuat.x
finalQuat.y = weight * fullRotationQuat.y + (1.0 - weight) * noRotationQuat.y
finalQuat.z = weight * fullRotationQuat.z + (1.0 - weight) * noRotationQuat.z