offset of rotation between 90 degrees angles

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By websterek

It’s slightly hard to explain what I’m looking for. But in general I need to find offset of rotation on one axis between 90 degrees angles. I need this to slightly rotate RayCast when the parent is on the curve (to better detect objects or obstacles on the curved route).

I’ve made this silly animation to explain it better :smiley:
enter link description here

And here is screen of example route with raycast and red arrow showing vector of movement:

The best for me will be getting this value between -1 and 1:
like this:

rotation 00 deg = 0
rotation 45 deg = 1
rotation 90 deg = 0
rotation 135 deg = 1
rotation 180 deg = 0
and so on…

rotation 00 deg = 0
rotation -45 deg = -1
rotation -90 deg = 0

So in general right value I can get using sin(deg*2) but only when rotation in in one direction (for example from 0 degree to 90) but in oposit direction (when rotation is still above 0 degree) it still returns the same value. How can i detect direction of rotation (clockwise or opposite)?

websterek | 2018-07-04 11:34

:bust_in_silhouette: Reply From: websterek

I’ve got this!

So I have use sin function with angle devided by 2 and (all) in abs() function to keep it above zero. Then returned value I’m multiplaying by rotation (before transform) - rotation (after transform) what’s gives me correct plus/minus value.

It’s simpler than I thought :wink: