3rd person camera view lock

Hey,

So the player controls a tank with two rotating parts. The bottom and the turret. I would like to have the camera lock on to the back of the body of the tank and rotate exactly like the tank bottom does.

My current version does follow behind the tank but it does not rotate accordingly, there will be a lag to rotate. I would like it to rotate exactly when the body does. Any help would be much appreciated.

Can I assign the camera’s position to the tank’s position and just increase the height and distance of the camera to desired? If so, how do I do that?

My current code:

Vector3 wantedPosition = transform.TransformPoint(transform.position.x, transform``.position.y - 50, -distance);
mainCamera.transform.position = Vector3.Lerp(mainCamera.transform.position, wantedPosition, Time.deltaTime * 2.0f);

Quaternion wantedRotation = Quaternion.LookRotation(transform.position + mainCamera.transform.position, transform.up);
mainCamera.transform.rotation = Quaternion.Slerp(mainCamera.transform.rotation, wantedRotation, Time.deltaTime * 2.0f);

Why not simply make the camera a child of the tank? The whole point of the interpolation thing is so that it doesn’t just snap straight to the position, but if that’s what you actually want then there’s a much easier way to do it.

If you make the camera a transform child, then you can just manipulate

camTransform.localPosition = whatever;

to have the camera move up and down and back and forwards as you please.

Im not great at C# so im not to sure how it works, but, unity come with a built in cammra follow system, simply possition the Main Cammra in the possition you want it and set it to “smooth follow” then change the options int he Inspector panal to fit your liking :slight_smile: