Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to make the player look around in unity 3d

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseLook : MonoBehaviour
{
    // Put this in camara
    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;

     void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

     void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90, 90);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }
}
Comment

how to make the player look around in unity 3d

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseLook : MonoBehaviour
{
    // Put this in the camara
    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;

    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90, 90);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: hydrogen fuels 
Csharp :: function on program stops unity 
Csharp :: inverse kinematics not working unity 
Csharp :: c# jump space 
Csharp :: how to mirror an image in vs forms 
Csharp :: C# convert random numbers in textBox to currency 
Csharp :: how to show error xtramessagebox in devexpress c# 
Csharp :: syoutube 
Csharp :: population of the world 
Html :: html space 
Html :: email regex html pattern 
Html :: htmjl favicons 
Html :: starting html 
Html :: connecting metamask to binance smart chain 
Html :: textarea placeholder css 
Html :: input acepta solo imagenes 
Html :: fa icons profile 
Html :: html body full height 
Html :: html import css 
Html :: iframe youtube autoplay not working 
Html :: prevent webpage zooming in mobile 
Html :: html how to make text not bold 
Html :: open new tab html 
Html :: textarea placeholder 
Html :: change input required text html 
Html :: code to start text from right in html in arabic 
Html :: add Youtube videos to a website html 
Html :: html align text right 
Html :: markdown mathjax rendering script 
Html :: refresh html document every 30 seconds: 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =