Question by
The_Gavster · Apr 11, 2017 at 05:25 PM ·
c#camerarotation
How do I control the camera with my mouse?
I am trying to get the camera in my game to rotate in the direction that I am moving my mouse. (Like Minecraft). I have written code that rotates the camera based on the input from the mouse X and Mouse Y Axis'. Here is what I have:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraController : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float MH = Input.GetAxis("Mouse X");
float MV = -Input.GetAxis("Mouse Y");
transform.Rotate(MV, 0, 0, Space.World);
transform.Rotate(0, MH, 0, Space.World);
}
}
Just moving the camera on one axis is fine, but when I add two axis' it starts to rotate on the z axis as well. I want to eliminate the movement on the z axis. How do I do this?
Comment