- Home /
Ensure free camera lines up behind player
I have a free standing camera right that I'm trying to line up behind the player, so the camera is always looking at the player, but set back just a little. It almost works, but the more I move the more it is offset behind the player. The parent camera right should always line up directly behind the player.
Hierarchy is setup as follows:
-Free standing cam rig ----Main Camera (child of free standing rig) -Player//get amount to rotate camera var rotationAngle = speed * Input.GetAxis("Mouse X");
//rotate player based on mouse
player.transform.Rotate(0f, rotationAngle,0f);
//Set camera right behind player
parentRig.position = targetPosition;
//Rotate rig around player
parentRig.RotateAround(player.transform.position, player.transform.up, rotationAngle);
//rotate camera in rig to look at character. Ideally we'd be lined up directly behind player, but if we need to offset the rig for panning purposes, this is here.
transform.LookAt(lookAt);
If I move forward/back/right/left without the mouse, all works ok but with mouse movement it just seems to start getting offset from behind the player - ie the camera rig no longer lines up behind the player when the player rotates and ends up looking at the player from an angle. The crosshairs on the screen then don't line up with where the player is looking since they are gui based and the player is no longer centered to where the camera looks.
Answer by suribe · Jun 19, 2014 at 02:35 PM
It might probably be much easier to just make the camera be a child of the player GameObject, a little bit behind him. So when you rotate the player, the camera will rotate automatically without you having to do anything at all.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151851im_/https://answers.unity.com/themes/thub/images/avi.jpg)