Smooth offset on a third person camera

I’m a beginner in Unity, but I’m trying to create a third person shooter with the emphasis being more on the point where the player is looking rather than the player itself.

So what I want to do is: the camera orbits the player, but is always offset over either side so the player is never in the middle. The offset should change depending on what direction the player is turning towards: if the player turns left, the camera offset should be on the left side of the player and if turning right, the offset would be on the right side.

Hopefully you get what I mean.I could’ve sworn I saw an example of this somewhere, executed on Unity but I can’t find it anywhere anymore. I’m currently using unmodified SmoothFollowCamera.js script for the camera.

EDIT: I forgot to mention that the camer should be looking at a gameobject called AimTarget. I have this piece already, the question is merely about the position of the camera, in relation to the player.

Thanks in advance.

In this part of the SmoothFollow script:

transform.position -= currentRotation * Vector3.forward * distance;

You see that the camera’s position is updated. That means that it’s here where you can add another line of code to make it not only be somewhere on the z axis, but also on the x axis:

transform.position -= currentRotation * Vector3.forward * distance + target.right * offset_x;

offset_x is a variable we have to declare in the main body; Set it to 2f for now:

public float offset_x = -2f;

Now you just have to check if the player is turning left or right (turnvector, mouse axis movement or whatever, depending on how you control your character). If hhe turns left, you just set the offset_x value to 2:

if(playerturnsLeft) {
     offset_x = 2;
}
else {
     offset_x = -2;
}

If you don’t use a gameObject target variable but rather just a Vector3 directly as the camera_s position to look at, you would use the camera’s transform.right Vector3 instead.