Unity 3D : Mouse Look Script
kali ini saya akan share tentang script yang saya buat untuk Unity 3D. script ini berguna untuk mouse look pada camera game terutama pada game FPS, dengan inputan melalui hardware mouse.
mouse look script ini dimasukan kedalam main camera dari yang terdapat pada objek, sehingga objek seakan-akan menjadi mata dalam game ( FPS )
dalam script ini juga terdapat :
- Look sensivity yang berguna untuk mengatur kecepatan pergeseran dari kamera
- Look Smooth Dump yang berfungsi untuk mengatur kelembutan dari pergeseran
check the script out yo ~
var lookSensitivity : float = 5;
@HideInInspector
var xRotation : float;
@HideInInspector
var yRotation : float;
@HideInInspector
var currentYRotation : float;
@HideInInspector
var currentXRotation : float;
@HideInInspector
var yRotationV : float;
@HideInInspector
var xRotationV : float;
var lookSmoothDamp : float = 0.1;
function Update () {
yRotation += Input.GetAxis("Mouse X")* lookSensitivity;
xRotation -= Input.GetAxis("Mouse Y")* lookSensitivity;
xRotation = Mathf.Clamp(xRotation,-90,90);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
}
@HideInInspector
var xRotation : float;
@HideInInspector
var yRotation : float;
@HideInInspector
var currentYRotation : float;
@HideInInspector
var currentXRotation : float;
@HideInInspector
var yRotationV : float;
@HideInInspector
var xRotationV : float;
var lookSmoothDamp : float = 0.1;
function Update () {
yRotation += Input.GetAxis("Mouse X")* lookSensitivity;
xRotation -= Input.GetAxis("Mouse Y")* lookSensitivity;
xRotation = Mathf.Clamp(xRotation,-90,90);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
}
No comments:
Post a Comment