Hi, I’m trying to get a camera to rotate continually in situ and to be able to Slerp to a specified angle of tilt above or below the horizontal plane (looking up or looking down). It’s not coming together for me. Please help.
myTransform.RotateAround (myTransform.position, Vector3.up, 20 * Time.deltaTime);
that line works to rotate but not the following in combination:
Quaternion.Slerp (myTransform.rotation, Quaternion.Euler (specifiedTiltAngle, 0, 0), Time.time * 5);
I’m still trying to understand all of this quaternion and rotation math, but I think I might have an idea why its not working. If I understand correctly, you’re wanting to have a stationary camera that can be rotated to look in all directions? If that’s the case, your RotateAround is rotating the camera around the y axis, then when you do your Slerp, you are rotating the camera around the world x axis since you are using Quaternion.Euler. I think what you are wanting to do is to rotate the camera around its local x axis, in which case you would use something like
var relativeRight: Vector3 = myTransform.TransformDirection(Vector3.right);
to get the local x axis as a vector. Then I think you can just do another RotateAround as such
Thanks Bauer for taking the time to think about my problem.
I’m afraid that makes my camera spin/rotate in a vertical plane while spinning/rotating in a horizontal plane. I want my camera to spin in the horizontal plane, yes, but to be able to move to a fixed angle of tilt (in a nice slerp) in the vertical plane and to keep that fixed tilt while rotating slowly in the horizontal plane (as in, I say to my camera look up to the sky when you’re rotating but not at a fixed point, OR look down at the ground when you’re rotating but not at a fixed point). I suppose I shall have to take a few days to sit down and study in detail the Unity commands in the hope that things become clear.
This works partially to do what I want.
The camera rotates slowly in the horizontal plane, that’s fine.
But I jump abruptly to a new tilt angle, camtilt.
I try to do a slerp to give me a gradual transition by substituting the following for the last line but it doesn’t work.
The camera continues to rotate in the horizontal plane but there’s no tilt at all of the camera.
That looks correct, if the myTransform.rotation = myRotation; is giving you the rotation you want then the other line should do the transition. I noticed you said you replaced the last line with your slerp line, did you make sure to assign the slerp to the transform.rotation?