- Home /
How to rotate a camera in WorldSpace CORRECTLY
So, im currently working on a small game in space, where you can build with blocks, i´ve got it working so far, but the camera script i am currently using is, well, not good.
Dont get me wrong it is working, but if i get upside down ( using Q and E ) it (of course) rotates the wrong way ( if i move the mouse up, the world appears to move down).
I can understand that since it is working in global WorldSpace.
I could need some help with getting it to work correctly
HERE IS THE CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FirstPersonCamera : MonoBehaviour
{
public float speedH = 2.0f;
public float speedV = 2.0f;
public GameObject Itself;
private float yaw = 0.0f;
private float pitch = 0.0f;
private float roll = 0.0f;
private void Start()
{
Cursor.visible = true;
}
void Update()
{
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
roll += Input.GetAxis("QandE") * 90 * Time.deltaTime;
transform.rotation = Quaternion.Euler(pitch, yaw ,roll);
}
}
Depends on what you expect. I guess it's not just the mouse but everything should alter the camera in its local space?
Your answer
![](https://koobas.hobune.stream/wayback/20220612213519im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make an object go the direction it is facing? 6 Answers
How do I turn 1 objects rotation into another objects movement direction? 1 Answer
Flip over an object (smooth transition) 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
Why the player is not rotating and moving at the same time ? 0 Answers