Camera Target Object relative to Player Object

I have a top down 2d game and I want the CameraTarget object to always sit 1f away in the direction the user is facing.

Since I don’t actually rotate my player to turn (i set anim floats based on input.getaxis) I can’t just set it as a child and it gets done automatically.

So I base its position off the getaxis from the controller. This is ran on the CameraTarget object;

// get controller direction
Vector3 movement_vector = new Vector3 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical"), 0f);

// if controller is pushed in a direction...
if (movement_vector != {

    // set camera to the player + controller direction
    transform.position = (player.transform.position + movement_vector);


This works as a start, but it doesnt always sit 1f away in the direction the player last pushed on the controller.


alt text

Any suggestions or ideas how I can adapt it to do that? I want it to move in a smooth arc if possible, but not sure of the maths involved.

if you are looking for the distance between the Camera and the player, i can give you a suggestion, i am currently learning unity too so pardon me if i am wrong here.

if you want to transform the camera position, make a camerafollow script and attach it to the camera.
In the update() write Camera.main.transform.position = new Vector3 (X POSITION,Y POSITION,1f);

XPOSITION and YPOSITION depend on you!