Camera movement
Hi,
I want my camera to follow my player in a 2D game so i putted my camera as a children of player but when I turn my player left, I use transform.eulerAngles to rotate my player sprite but I dont want my camera to rotate too and I don't know how to do this.
Answer by Measurity · Dec 26, 2015 at 10:28 PM
Don't make the camera a child of your player.
Create a script for the Camera and add it as a component with following code:
public Transform Target;
void LateUpdate()
{
transform.position = Target.position;
}
Now go back to Unity and drag the player object into the Target field of the script. You are now free to rotate the player without affecting the camera.
Tanks. I just had to change a little because the Camera Z axis mustn't be the same as the target's. transform.position = new Vector3 (Target.position.x ,Target.position.y , -10);
Your answer
Follow this Question
Related Questions
Camera moves impossibly fast, and can't see any object 1 Answer
CS1216 error 0 Answers
Either my camera moves/changes size or my scene does... But why? Unity 2D 0 Answers
My explosion material is shown from the back of the screen but not from front 1 Answer
Can I use 2d Tilemap in a 2D game that uses 3D camera? 0 Answers