- Home /
How can I rotate one axis locally, and another globally?
I'm making a game where a car drives around a sphere (basically), and I'm having problems with the camera controls.
The up-down rotation is supposed to be local, and the left-right rotation needs to be global. I'm having problems with setting this up.
So far, my code looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour {
public int widthX = Screen.width;
public int widthY = Screen.height;
public Object target;
public float posX;
public float posY;
// Update is called once per frame
void Update () {
posX = Input.mousePosition.x;
posY = Input.mousePosition.y;
transform.localRotation = Quaternion.Euler (posY / 4 , transform.localRotation.y, 0f);
transform.rotation = Quaternion.Euler (transform.rotation.x, posX, 0f);
}
}
Comment
Your answer
Follow this Question
Related Questions
Local Rotation and then Global Rotation 1 Answer
Simulating different gravity, how to make falling platform fall in the desired direction? 1 Answer
Why is it moving locally instead of globally? 1 Answer
Is there a way to use MoveRotation() globally? 0 Answers
Combining 2 Rotations: Global and Local 2 Answers