- Home /
Quaterion.Slerp + Lookat, camera flipping
I've got a little ship flying around on a sphere and am trying to make a slightly more sophisticated camera that "smooth" follows it.
I basically Lerp the camera's position to a point above the ship, along a Vector line going from the origin on the planet to the ship (i.e. along the normal of the surface where the ship is).
I then tried using "Quaternion.Lookat" to get the camera to look at the ship appropriately from wherever the camera is (i.e. usually directly overhead, the ship, or lagging close behind). This looks very nice generally, but a weird thing happens: as you go around the globe, at a certain point, the camera flips wildly 180 degrees (while still looking at the ship). It certainly always keeps it in view, but is a bit jarring to see, and I can't work out how to stop it.
Does anyone have a solution for this, or pointers to the sort of thing I should be attempting here (Wild stab in the dark, it feels like i might need to constrain one of the axes of the Quaternion to never rotate, since even though it's a 3d sphere, it's really more like a 2d plane, and only needs two axes to appropriately point to the ship.
Thanks! Mike
Twitter: @runonthespot