Hello
I am trying to wrap my head around bone rotations through code, I am almost getting what I want but not quite.
I want the bottom half of my body to move toward movement (Which I have), while the upper part of the body is always looking forward. I basically have what I want except for the Spine bone that I am rotating just above the hips is kind of… freaking out… and I don’t understand why…
So… two methods with the best results ive got so far
All this code is in lateupdate
- Best results so far
torsoBone.transform.LookAt(testObj.transform, Vector3.forward);
“testObj” is the little cube in front of me that is just a child of the top parent object. The character model is also a child of that top parent object, so they are in the same place in the hierarchy.
This is what I get facing East (not really east of course just a reference)
The above gets me the best results. It all works perfectly, until I turn west. (Pic below)
I assume this has to do with world space and local space, I’ve looked how to do it in my scenario but cant get anything to work so far.
- Second best
float damping = 5f;
Vector3 lookPos = transform.position - Camera.main.transform.position;
lookPos.z = 0;
Quaternion rot = Quaternion.LookRotation(lookPos);
torsoBone.transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * damping);
This works perfectly in all directions except for my body is rotated at a 90 degree
In the above picture ive tried to force the bone to rotate the right way but it will not move not matter what I try.
Anyway, if anyone could help me out or point me in the right direction I would really appreciate it. Let me know if you need more info from me, I am glad to give.