How to calculate actor Roll from two Input Axes?
Hey everyone, I have a problem that I've been trying to solve for 4 days now and I can't find any help on this specific problem, so I came to the forums for help!
I'm trying to make a 2D movement control for a player actor. The character is in a 3D space, but is restrained to move on a 2D plane. Basically its a sideview game with a swimming fish that the player controls, who can swim up, down, left right. I'm trying to make the fish face the direction of the movement, but I just cannot figure out how to calculate the rotation.
My question (marked on the 2nd screenshot): How can I calculate a Roll value from the WASD inputs? So if I press W and D (going up-right diagonally), it should return 45° Roll. If I go straight down it should return 180° and so on. I figured I can use a Make Rotator from [something] or Make Rotation from Axes or such, but they require multiple Vector input nodes and I don't know where to plug what, and how that would work.
What didn't work: I have made many many attempts previously, with trying to multiply Input values by 90, subtract from 180 if I'm also moving down, a ton of branches and variables, but it was a huge mess, and it wouldn't work properly. Most of the time there was a random spin, if I went over 180 (so 178, 179, 180 then jumped into negative -179). With certain methods it went properly into 181, 182 etc. but it would do a crazy 360 spin around to "continue" the rotation from the other way around.
In other methods, it did the spin seemingly randomly, say going from 220 to 221 degrees, even though it didn't go into negative values.
If anyone has an answer on how to get this "target rotation", please let me know, I've been going insane over trying to get this to work, and I'm convinced that I'm just unaware of a simple method that can do this! Thank you so much in advance!
asked Oct 03 '18 at 07:42 PM in Using UE4
Me again, I managed to solve the issue eventually and I came back to upload the answer in case anyone else might run into the same problem/wants to do the same thing.
In addition to handling 2-axis input correctly, this method (using rotator) also eliminated the random spin around the other way when passing into negative degrees, as I believe rotator variable types can handle this internally!
I hope this will be able to help someone in the future, in case someone finds this post. I believe this will work if your character moves on another plane (let's say top down view, moving in world XY) by changing the pin connections around. Have fun makin' games guys! :)
Follow this question
Once you sign in you will be able to subscribe for any updates here