Cool Camera movement with Vector3.Slerp

I made the camera smoothly follow the rocket using a reference point away in the Z axis, and making a slerp. I’m not exactly if I did right, though (I wish it could be smoother). Here’s the result:

To do that, I create an empty object (CameraBase) and placed it far in the z axis (I used 50). Then, I attached an script to it, that receives as SerializableFields the Camera object and the Rocket transform object… and finally, I created another SerializableField with a float to help calculate a distance for the camera. The update method became as follows:

    void Update()
        //interpolates a new position on a sphere based on the CameraBase and the Rocket
        var position = Vector3.Slerp(transform.position, rocket.position, 1);
        //caches the camera current position - to keep y and z values
        var camPos = camera.transform.position;
        //slides the camera in the x axis with the interpolated position, but keeps y and z
        camera.transform.position = new Vector3(position.x * distance, camPos.y, camPos.z);
        //keep the camera pointing at CameraBase
        camera.transform.LookAt(transform, Vector3.up);

What do you guys think???

Very cool. Does the camera follow the ship movement or does it pan automatically?

Privacy & Terms