how to i convert a local rotation to a global rotation for the object?

Hi

I need to use Rigidbody.rotation which seems to take only a global rotation.
The problem is that the value I get from other functions I’m using is the local rotation of the object, so I need to convert that local rotation quaternion into the corresponding global rotation to pass to the rigidbody.rotation as a parameter.

It must be simple but i’m failing badly so far

2 Likes

3rd google link :wink: Transform global quaternion from local quaternion - Questions & Answers - Unity Discussions

yeah, I googled and found that one too but it didn’t work. Not sure if it was my fault or the way to do it on there is wrong. In my case also I don’t have a “parent” to compare to, because my object is the parent itself.

If the object has no parent, then the local and world rotation is the same.

2 Likes

doh… I hide into a hole. Brain fart.

2 Likes

Hello all,

I am stuck in this problem that seems pretty obvious and common. I googled it a lot and all I tried is not working.

I am trying to convert my local rotation to world rotation to apply it to rigidbody. Whatever I try, I always end with rotation around world axis.

This line rotate around world axis.
_rigidbody.rotation = Quaternion.Euler(cameraRotation);

I want to convert cameraRotation (Vector3 euler angle local rotation) to world rotation.

Any tips ?

Tanks !

.rotation is world rotation. If you want to mutate it’s local rotation, use .localRotation.

There is no .localRotation for a rigibody. If you move your transform directly with a non kinematic rigidbody object. It is gonna get messy.

Well local rotation can be viewed as the rotation - parent.rotation (transform.rotation * Quaternion.Inverse(parent.rotation). So if you want to ‘set’ a local rotation of a rigibody, you can generate a world rotation by combining your ‘local’ rotation and the rotation of the parent, and applying that to the rigidbody.

1 Like