# Get Actor x, y, z rotation angle in shader

**URL:** <https://forums.unrealengine.com/t/get-actor-x-y-z-rotation-angle-in-shader/155362>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [December 21, 2020, 2:08am UTC](https://forums.unrealengine.com/t/get-actor-x-y-z-rotation-angle-in-shader/155362 "2020-12-21T02:08:45Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![Poncho\_a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poncho\_a](https://forums.unrealengine.com/u/Poncho_a)\
**Post date:** [October 5, 2024, 9:39pm UTC](https://forums.unrealengine.com/t/get-actor-x-y-z-rotation-angle-in-shader/155362/14 "2024-10-05T21:39:51Z")

</div>

Hi !  
I know it’s already an older post, but since Google took me here, here’s my solution to fix the weird values.  
It’s not perfect, but there is only a couple of specific angles where the Y value is wrong, and it is only a few angles off.

```auto
float3x3 WtoL = LWCToFloat(GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal);
float sy = sqrt(WtoL[0][0] * WtoL[0][0] + WtoL[1][0] * WtoL[1][0]);

bool singular = sy < 1e-6; // If true, gimbal lock is likely

float x, y, z;
if (!singular) {
    x = -atan2(WtoL[2][1], WtoL[2][2]);
    y = -atan2(-WtoL[2][0], sy);
    z = atan2(WtoL[1][0], WtoL[0][0]);
} else {
    x = -atan2(-WtoL[1][2], WtoL[1][1]);
    y = -atan2(-WtoL[2][0], sy);
    z = 0;
}

float3 R = float3(x, y, z);
return R < 0 ? (2 * pi - abs(R)) : R;

```

There is probably a better way to fix this, as I am only barely cognisant when it comes to angular mathematics…

---

_[View the full topic](https://forums.unrealengine.com/t/get-actor-x-y-z-rotation-angle-in-shader/155362)._
