• News

• Industries

• Learning & Support

• Community

• Marketplace

# Remapping joystick rotation to 0-1

Hey guys. I’m working on a feature of my project that has stumped me. I want to somehow take the rotation information from the controller joystick and turn a 360 degree movement into a number I can use. How I want to use it is, starting from UP or y -1, a full 360 degree clockwise movement will fill a progress bar once. It’s a timed mini game, so the faster you can rotate the joystick, the faster you can fill the progress bar multiple times. It’s not a new concept but I’m having a hard time figuring out how to take the x -1, 1 and y -1 1 coordinates and turn them into something I can use. Does it make sense to convert it to degrees, radians or a simple 0-1? I haven’t been able to get any of those to work. Any help is appreciated.

Thanks

https://www.mathsisfun.com/geometry/unit-circle.html

Study it, it’s pretty much everything you need. You’re looking at taking sin/cos of the X/Y axis values and converting them into a degree/radian. 360 degrees is 2pi radians (6.28319)

You could use Atan2, just plug in x and y joystick movement. Although I think this returns a value between -180 and 180. But it’s something.

I got this working. It ended up being pretty simple. The multiply by -1 reverses the direction and if 0 is at the top or bottom.

(Atan2(x/y) + 360) % 360 will give you a mapping from 0 - 360 based on your input scalar axis (0 - 1).

## [ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_178425_1575326346261_484”}[/ATTACH]https://forums.unrealengine.com/core/image/gif;base64 ​

Atan2(x/y) will return you a mapping of something like this -

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_178426_1575327067853_749”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

Goodluck and have fun