Question by
pabloferrariferrari · Oct 09, 2019 at 07:24 AM ·
camerarotationtransformfirst-person-controllerfirst person controller
Transform.Rotate x and y rotate z, where z is 0
I have a code to a first person camera, he must to rotate in X and Y, but rotate in Z too. What I do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Look : MonoBehaviour
{
public float sensitivity;
void Update() {
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
float yMovement = mouseX * sensitivity * Time.deltaTime;;
float xMovement = mouseY * sensitivity * Time.deltaTime;
transform.Rotate(xMovement, yMovement, 0f);
}
}
Comment
what you are doing absolutly fine. my guess is may other script is effecting the camera to rotate z.
There isn't another script, and keep rotating z.
Bro your script is not the reason for the z rotation. Can you try to do the same thing in a new scene where the scene has only one object that contains the above script.
Your answer
Follow this Question
Related Questions
Trouble Implementing First Person Camera 1 Answer
Movement in the direction the user is facing with arrow keys 0 Answers
Record and replay movement 0 Answers
FPS Weapon Clipping 1 Answer