Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

First Person Camera

Discussion in 'Scripting' started by spencer_white, Dec 20, 2015.

  1. spencer_white

    spencer_white

    Joined:
    Nov 9, 2015
    Posts:
    37
    I am working on a first person controller, and I decided the hardest part would be to get the camera to follow the mouse. I was correct.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class FirstPersonScript : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update () {
    12.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    13.         transform.rotation = Quaternion.Euler(ray.direction);
    14.     }
    15. }
    16.  
    This code sort of works, as the camera moves when I move the mouse, but not how I want it to. The camera rotation seemingly stays in one place.
     
  2. buckius82

    buckius82

    Joined:
    Nov 19, 2013
    Posts:
    40
    Theres a first person controllor in the standard assets