![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | wowzzers |
I have a camera that looks at some direction, using look_at function. The camera is a child of a character. I copy the transform to a character’s bone. Looking left and right works but when camera looks up, the bone looks down.
Is there a way to copy camera’s transform to a bone (for example head bone of a character) but invert it only by one axis?
Edit: Kind of made it to work. I’m not sure.
Edit 2: No! Actually it doesn’t work. It distorts the mesh.
My code is something like this:
$camera.look_at(target.translation, Vector3.UP)
var t = $camera.transform
var t_inverted = t.inverse()
$character/skeleton.set_bone_custom_pose(
$character/skeleton.find_bone("head"),
Transform(t_inverted.basis.x, t_inverted.basis.y, t.basis.z, t.origin)
)
Is this correct or there’s a better way?
Managed to get it working. Instead of copying the transform I first get the rotation. Then I create a Quaternion with inverted X component. And then the Transform based on this Quaternion.
var rot = $camera.rotation
var quat = Quat(Vector3(-rot.x, rot.y, rot.z))
var trans = Transform(quat)
$character/skeleton.set_bone_custom_pose(bone, trans)
But if there’s a proper way to do it, please answer. Thank you.
wowzzers | 2020-01-28 15:05
keep in mind that the Transform.look_at()
function looks twoards a point from your Transform.origin (current position). It’s not computing the direction from 0,0,0. Not saying that’s your problem, but it might.
Jason Swearingen | 2020-01-28 15:05