- Home /
Question by
darkdoom973 · Nov 02, 2021 at 03:42 PM ·
rotationscripting probleminputcharactercontrollermathf.clamp
After adding script for rotation to look up down, look left right stopped working,After writing code for the rotation for looking up down, looking right left stopped
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseLook : MonoBehaviour { public float MouseSensitivity = 100; public Transform PlayerBody;
//This i created for up down
float xRotation = 0f;
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;
PlayerBody.Rotate(Vector3.up * mouseX);
//This is the script for up down
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, mouseX, 0f);
}
} , using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseLook : MonoBehaviour { public float MouseSensitivity = 100; public Transform PlayerBody;
//This i created for up down
float xRotation = 0f;
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;
PlayerBody.Rotate(Vector3.up * mouseX);
//This is the script for up down
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, mouseX, 0f);
}
}
Comment