Initial commit
This commit is contained in:
29
Assets/Scripts/MouseLook.cs
Normal file
29
Assets/Scripts/MouseLook.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MouseLook : MonoBehaviour
|
||||
{
|
||||
public float mouseSensitivity = 100f;
|
||||
|
||||
float xRotation = 0f; // untuk batasi rotasi vertikal
|
||||
|
||||
void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked; // supaya kursor hilang dan mouse terkunci di tengah layar
|
||||
}
|
||||
|
||||
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, -90f, 90f); // supaya gak muter 360 vertikal
|
||||
|
||||
// rotasi vertikal kamera (pitch)
|
||||
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
|
||||
|
||||
// rotasi horizontal player (yaw)
|
||||
transform.parent.Rotate(Vector3.up * mouseX);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user