Question by
Corvo_Dawnstar · Apr 22, 2019 at 04:36 PM ·
2d-platformer
How can I lock my main camera's y position?
In building a 2D game, I have my main camera following my player object through a camera control script. I'd like to prevent the camera from going up with the player as they jump or down if they happen to fall in a pit. This is the code i'm using: public GameObject player; private Vector3 offset;
void Start()
{
offset = transform.position - player.transform.position;
}
void LateUpdate()
{
transform.position = player.transform.position + offset;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612200011im_/https://answers.unity.com/themes/thub/images/avi.jpg)