- Home /
Transform global quaternion from local quaternion
I'm making a racing game camera.
I have the "Vehicle" wich moves arround and I have a camera following the vehicle. This camera is held by an empty gameObject wich I'll name CameraHolder.
In the Hierarchy the Camera is son of the CameraHolder, wich is son of the Vehicle.
- Vehicle
- CameraHolder
Camera
- CameraHolder
The camera is always at the same distance from the CameraHolder and I rotate the cameraHolder using mouse.
angleX += Input.GetAxis("Mouse X")*sensitivity;
angleY += Input.GetAxis("Mouse Y")*sensitivity;
var wantedRotation : Quaternion = Quaternion.Euler(-angleY, angleX, 0);
transform.rotation = toGlobal(wantedRotation);
The problem is that I want angles to be relative to the Vehicle's rotation so I need to transform the local Quaternion wantedRotation generated from angles, to global Quaternion using the Vehicle rotation quaternion in some way.
I need some way of toGlobal() function.
Probably, if it's not possible I'll need to work on Euler Angles or Directions.
Answer by ScroodgeM · Aug 13, 2012 at 06:26 PM
sol 1
use local rotation directly
transform.localRotation = wantedRotation;
sol 2
use offset from another object's rotation
transform.rotation = otherTransform.rotation * wantedRotation;
I used localRotation before but failed, just found that it was my fault for using transform.rotation on my operations to assign to the transform.localRotation later. It works now. Thanks!
Answer by Meceka · Mar 27, 2020 at 03:53 PM
You can get the global rotation based on the parent objects global rotation and a local rotation like this;
Quaternion worldRotation= transform.parent.rotation * localRotation;
Your answer
Follow this Question
Related Questions
Help with local and world translation.position 0 Answers
Maya objects with different transforms. 1 Answer
use world axis when using transform.rotate 3 Answers
Simulating different gravity, how to make falling platform fall in the desired direction? 1 Answer
Vertex Coordinates to Global Vector3 2 Answers