Help rotating camera script
Hi, I'm starting a new project and for the first time, I'm doing a 3d project.
On my camera script, I want the camera to rotate around my character when the player press Left Alt. The character must stay at the same place
When I press left ALT the camera is rotating around my character. But when I release the left Alt at any position, the character rotates to the position I release the ALT. I just want the camera to freely move around the character when I press left ALT and when I release the camera must return at the back of the character.
Here is my code :
public float rotationSpeed = 1f;
public float zoomSpeed = 1f;
public Transform Target, Player;
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
private void LateUpdate()
{
CamControl();
}
void CamControl()
{
mouseX += Input.GetAxis("Mouse X") * rotationSpeed;
mouseY -= Input.GetAxis("Mouse Y") * rotationSpeed;
mouseY = Mathf.Clamp(mouseY, -35, 60);
transform.LookAt(Target);
if (Input.GetKey(KeyCode.LeftAlt)) // the bug is probably here
{
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
}
else
{
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
Player.rotation = Quaternion.Euler(0, mouseX, 0);
}
}
Help me, please :)