- Home /
Question by
EA1S · Jan 22, 2021 at 12:35 PM ·
rotationcamera rotate
how to set z rotation to be always 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouseLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform playerBody;
// Start is called before the first frame update
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);
playerBody.Rotate(Vector3.right * -mouseY);
}
}
Comment
Answer by logicandchaos · Jan 22, 2021 at 02:53 PM
put this last in update:
playerBody.rotation=new Vector3(playerBody.rotation.x,playerBody.rotation.y,0);
or you can set the constraints in the inspector.
Your answer
Follow this Question
Related Questions
How to Rotate FPS Camera independent of Parent Player Object while WallRunning ? 0 Answers
[Solved :D] Camera auto turns 180° from its init position on Play (Animated GIF Included!) 1 Answer
How to make that the camera will not go through the walls? 1 Answer
How Do i Prevent The First Person Camera From Turning 0 Answers
Camera not rotating 1 Answer