- Home /
how to follow the player?
hi, i making a 2d game, the camera has to follow the player who has 4 transformations that are two different object (they are activated and deactivated with (SetActive)) they have the same tag. When the player passes over some element it undergoes the transformation, the object chenges and the camera stop folliwing him, how can make the camera always follow the player when gameObject change? Thakss!!
bruh im stumped. So do you mean that the player undergoes a transformation at a point and the player object changes? And now you want the camera to follow the changed player?
Exactly, the camera must follow the player every time he changes transformation
Answer by HappyPixel27 · Jul 28, 2020 at 12:24 AM
Make a transform variable for each different position. Make the camera's transform equal to the transform that you want the camera to follow. Have another vector 3 with an offset value if you wish.
public GameObject Player;
public Camera mainCam;
private void Update()
{
mainCam.transform.position = new Vector3(Player.transform.position.x, Player.transform.position.y, mainCam.transform.position.z);
// you dont want the mainCam's z position to equal the player. Just the x and y.
}
the idea is good, but if the player collides with an enemy changes the random transformation, so I can’t give a fixed position..
Your answer

Follow this Question
Related Questions
Changing Character Controller Height, But Main Camera Doesn't Follow Properly? 1 Answer
Camera zooming in and out problem 0 Answers
How to make the bodyParts to follow same places and directions as the player? 0 Answers
how to make the camera follow the player only in one axis (the z axis) 0 Answers
"Follow Target" script with a prefab (C#) Help me please! 1 Answer