- Home /
Question by
Some-Random-Coder_ · Apr 25, 2021 at 05:55 AM ·
cameracamera rotate
Problem with Camera rotating
Hello, I am relatively new to Unity and I am working on an fps arena kind of game, but my camera is not working. There are no compiler errors either. Here is the code, can someone help?
public Transform player;
public Vector3 offset = new Vector3(0, 2, 0);
public float camPosX;
public float camPosY;
public float camPosZ;
public float camRotationX;
public float camRotationY;
public float camRotationZ;
public float turnSpeed;
private void Start()
{
offset = new Vector3(player.position.x + camPosX, player.position.y + camPosY, player.position.z + camPosZ);
transform.rotation = Quaternion.Euler(camRotationX, camRotationY, camRotationZ);
}
private void LateUpdate()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * turnSpeed, Vector3.right) * offset;
transform.position = player.position + offset;
transform.LookAt(player.position);
}
Comment