How to lower and raise height the camera height
Im currently creating a camera that can be used to navigate a scene with wasd. Along with being able to rotate the camera with right mouse click. Im trying to increase and decrease the height of my camera with 'Q' nad 'E'. I thought it would be similar to the rotate function however it seems its not. Any help is appreciated.
Variables
public float rotSpeed;
private Vector2 mouseLook;
Rotate function
private void HandleRot()
{
float horizontal = 0;
if (Input.GetMouseButton(1))
{
horizontal = Input.GetAxis("Mouse X");
}
Vector2 look = new Vector2(horizontal, 0f);
mouseLook += look * rotSpeed;
transform.localRotation = Quaternion.AngleAxis(mouseLook.x, transform.up);
}
Function for changing height of camera
private void HandleHeight()
{
float vertical = 0;
if (Input.GetKey(KeyCode.Q))
{
vertical = -1f;
}
if (Input.GetKey(KeyCode.E))
{
vertical = 1f;
}
Vector2 look = new Vector2(vertical, 0f);
mouseLook += look * rotSpeed;
transform.localRotation = Quaternion.AngleAxis(mouseLook.y, transform.up);
}
Your answer
Follow this Question
Related Questions
Help With Camera rotation on X and Y Axis (Target Focused) 1 Answer
Why is my camera shaking when I use my chaser script on something? 0 Answers
Making the camera rotation in line with the ball 1 Answer
Does anyone know the script for a smooth camera follow of the main game object? 8 Answers
When attaching my custom camera script camera shakes when player starts to move fast. 0 Answers