- Home /
Bone Rotation on X (or any) axis Issues
Okay, so I'm trying to make my characters spine rotate based off the rotation of the camera. I've had no luck so far and have done plenty of googling and managed to work around a bit, but still to no luck. First things first. I found that you can't seem to rotate the bones of the character unless done in a late update. So I tried a basic code like so and it worked.
public Transform Spine;
void LateUpdate()
{
Spine.transform.Rotate(30, 0, 0);
}
The character looks up at a slight angle as intended. Great! Now to make it based off the camera's rotation so the character will actually be looking up when the player does. So I made a float. Actually I started with Quaternions but had issues with it. SO I decided to make it as simple as possible. I created the float SpineX, then tried to base the rotation the exact same way but using the float instead of 30. So like so:
public Transform Spine;
public Transform CameraControlObject;
public float SpineX;
void LateUpdate()
{
Spine.transform.Rotate(SpineX, 0, 0);
}
void Update()
{
SpineX = CameraControlObject.transform.rotation.x;
}
So I thought this would work, but it doesn't rotate him at all. And when I did something similar using Quaternions, Vector3, etc. I had similar luck where it wouldn't rotate properly. But at least it rotated. I am gonna try and rewrite it back into my Vector3 format and play with that because at least that way it did rotate. Maybe I can correct it.
Have you tried a different Space parameter (relativeTo)?
Answer by Foestar · Jun 23, 2017 at 10:22 PM
This has been solved. I used the following:
Spine.transform.rotation = CameraControlObject.transform.rotation;
And noticed my bones were off on the orientation. So to solve it I placed an empty object that aligned with my bones so I didn't have to deal with exporting/rigging orientation within a 3D modeling program. Then I placed the camera inside of that and made sure it was set properly.
Your answer
Follow this Question
Related Questions
How to get angular difference? 2 Answers
Align GameObject to Terrain angle 2 Answers
Creating a multiple part turret what locks onto certain axis. 4 Answers