#my looking code
1 messages · Page 1 of 1 (latest)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class looking: MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 0f;
public float sensitivity = 100f; // increase this value to increase the camera rotation speed
// 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, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
void Start()
{
playerBody = GameObject.FindGameObjectWithTag("Player").transform;
}
}
You should post code correctly so it's easier to read: !code
Also you should not be multiplying mouse input with Time.deltaTime since mouse input is not tied to your FPS.
For the rotation I'm not sure? Never seen it made like that. You're better off accumulating the value into a variable and apply it once like you're doing for xRotation