- Home /
Mouse Look Script
I found this video about mouse look command https://www.youtube.com/watch?v=_QajrabyTJc&ab_channel=Brackeys
It works on video but not working on my project. Is it some problem about unity version?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class karakter_kontrol : MonoBehaviour { public float sens = 100f; public Transform body; float xrotation = 0f; void Start() { Cursor.lockState = CursorLockMode.Locked; }
void Update()
{
float mouseX = Input.GetAxisRaw("Mouse X") * sens * Time.deltaTime;
float mouseY = Input.GetAxisRaw("Mouse Y") * sens * Time.deltaTime;
xrotation -= mouseY;
transform.localRotation = Quaternion.Euler(xrotation, 0f, 0f);
body.Rotate(Vector3.up * mouseY);
}
}
What exactly is not working ? Can you explain a bit more ?
Everything is going wrong. I cant look right or left, i can look up and down but its reversed.
Answer by Drayanlia · Mar 07, 2021 at 11:54 AM
For the reversed look up and down just try changing this xrotation += mouseY;
.
I then suspect you have to make the body a parent of the maincamera which this script is attached to.
Your answer
Follow this Question
Related Questions
how to make teleporting marker 0 Answers
How Do I Make My Weapon Follow My Cursor? 0 Answers
ui problem 0 Answers
Local High Score with Game Over Scene 1 Answer
Best way to find refrences. 0 Answers