How to make Slerp and single-axis rotation get along
My game object is a ring around a ball. I want the ring to always be parallel to the ground, which I achieved. I also want to be able to spin it along its y axis, which I can also do. What I can't do is both of those things at once. Spinning the ring seems to break the slerp and I don't really know why.
My code:
if (Input.GetKey ("e"))
ringswivel += 1;
if (Input.GetKey ("q"))
ringswivel -= 1;
RaycastHit leray;
if (Physics.Raycast(transform.position, -transform.up, out leray)){
Quaternion tilter = Quaternion.FromToRotation(transform.up, leray.normal);
transform.rotation = Quaternion.Slerp (transform.rotation, tilter, .1f);
transform.rotation = Quaternion.Euler (new Vector3 (transform.rotation.eulerAngles.x, ringswivel, transform.rotation.eulerAngles.z));
}
I don't fully understand how quaternions work so I'm sure it's some minor adjustment, but there's no way I'm figuring it out by myself.
Your answer
Follow this Question
Related Questions
Rotate on Transform.localeulerAngels smoothly 0 Answers
Player's rotation gets stuck when pressing two movement keys together 0 Answers
Unity2D Choppy Slerp Update,,Rigidbody rotation choppy in update 0 Answers
Can't really grasp how to keep my player level on X and Z while using LookRotation 0 Answers