I'm making a game were the player has a spotlight and explores a few dungeons (in first person). I already made the player move but I actually have a doubt for camera rotating. I've been looking in a few forum but the issue wasn't exactly the same at mine and I'm new in Unity. The question is: How can I do to move my camera while dragging the mouse around the screen for the player to see what's happening around him?
Mouse dragging detection - Unity3D
2.1k views Asked by Roman Panaget At
2
There are 2 answers
0
On
Check This http://unity3d.com/learn/tutorials/projects/survival-shooter/player-character
void OnUpdate() { Turning() }
void Turning () { // Create a ray from the mouse cursor on screen in the direction of the camera. Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition); // Create a RaycastHit variable to store information about what was hit by the ray. RaycastHit floorHit; // Perform the raycast and if it hits something on the floor layer... if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask)) { // Create a vector from the player to the point on the floor the raycast from the mouse hit. Vector3 playerToMouse = floorHit.point - transform.position; // Ensure the vector is entirely along the floor plane. playerToMouse.y = 0f; // Create a quaternion (rotation) based on looking down the vector from the player to the mouse. Quaternion newRotation = Quaternion.LookRotation (playerToMouse); // Set the player's rotation to this new rotation. playerRigidbody.MoveRotation (newRotation); } }