- Home /
Question by
happybro96 · Dec 21, 2019 at 09:06 PM ·
cameraangle
Why my camera's z angle keeps changing
i'm new to unity so sorry if i say something stupid. i have a ball falling in my game and a camera attached to it. the camera is a child of the ball. when player dies the ball position resets and the camera follows. But the problem is that the Z angle of the camera changes every time the ball re spawns (the player dies). i want the the camera to always have a Z angle of 0. here's the code for the ball and the camera respectfully:
private Vector3 startPos = new Vector3(0f, 80f, -1.5f);
public void ResetBall()
{
transform.position = startPos;
FindObjectOfType<CameraController>().ResetCamera();
}
cameras code:
{ private float offset;
// Start is called before the first frame update
void Awake()
{
offset = transform.position.y - target.transform.position.y;
}
// Update is called once per frame
void Update()
{
Vector3 curPos = transform.position;
curPos.y = target.transform.position.y + offset;
transform.position = curPos;
}
public void ResetCamera()
{
transform.eulerAngles = new Vector3(90f, 180f, 0f);
}
}
Comment