- Home /
Slerp with rotations from different spaces
I'm trying to create a character controller for the iphone that will rotate the upper body of a character. It works by taking the input from a touch joystick, creates a vector that's effectively in world space and then uses the rotation of that vector to rotate a bone in the character. Unfortunately the local space of the bone is very different than world space. So it doesn't rotate correctly. Here's the code that I'm using...
function CharacterRotation()
{
if (combatJoystick.position != Vector2.zero)
{
rotationAmount = (minRotationSpeed + maxRotationSpeed * combatJoystick.position.magnitude) * Time.deltaTime;
aimVector = Vector3 (combatJoystick.position.x, 0, combatJoystick.position.y);
aimRotation = Quaternion.LookRotation(aimVector, Vector3.up);
bone.transform.rotation = Quaternion.Slerp(bone.transform.rotation, aimRotation, rotationAmount );
print ("Rotation happening");
}
}
If I add a null object to the character with a local space similar to world everything works great except it breaks all the animations :-(
The models I'm using are prefabs so fixing it bones isn't really an option for me, moreover, I'd like to generically solve the problem so that it's easy for me to reuse the controller with other purchased models.
Any idea how I can get this to work right?
Thanks!
PS, I know the head look controller can do something like this, but that's overkill for what I'm trying to do and the unity asset store says it's not supported on the iPhone, which is an issue for me since my target platform is the iPhone/iPad.
Note: updated code for clarity (changed focus to bone).
Sorry,that's a typo. Focus and bone are the same thing. I was trying to clarify my code for the question. I've updated for clarity.