Question by
thuner2007 · Apr 04, 2021 at 04:49 PM ·
rotationrigidbodywithoutpls
freeze Z rotation without rigidbody
Hey! I make a game and i have a problem with my code. I want do freeze the Z rotation of my Gameobject without a rigidbody.
Here is my Code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraController : MonoBehaviour { //variables [SerializeField] private float mouseSensitivity;
//references
private Transform parent;
private void Start()
{
parent = transform.parent;
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
rotate();
}
private void rotate()
{
float mouseZ = 0;
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
//parent.Rotate(Vector2.up, mouseX);
//
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
//parent.Rotate(Vector2.left, mouseY);
parent.transform.Rotate(xAngle: mouseY, yAngle: mouseX, zAngle: mouseZ);
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotating rigidbody problem 0 Answers
Question About NavMesh Agent and rotation 1 Answer
[VR] Rigidbody.AddForce() following controllers rotation 0 Answers
DESPERATE How to align transform.up with another vector3 (direction) ? 1 Answer
Player rotates spastically on all axes when camera is turned 0 Answers