How to combine negative and positive float in ONE float?
I'm trying to create 360 locomotion using a hardware-controller but unfortunately it didn't went as expected. The issue I have is that I cannot read the joystick as a joystick and it collects only information about up, down, left and right.
So in summary I ended up with 4 floats, instead of 2 therefore I cannot activate my animator controller with the following code:
animController.SetFloat("Horizontal", horizontal);
animController.SetFloat("Vertical", vertical);
These are the floats i currently have:
float up = //from 0 to 1
float down = //from -1 to 0
float left = //from -1 to 0
float right = //from 0 to 1
My question is how to reconfigure the 4 variables into 2?
E.G. the way i want the variables to be is as follows so that i can activate my animator controller as mentioned above:
float horizontal = //should be from -1 to 1
float vertical = //should be from -1 to 1
animController.SetFloat("Horizontal", horizontal);
animController.SetFloat("Vertical", vertical);
Answer by streeetwalker · Sep 15, 2020 at 09:10 AM
@loizos-95b, perhaps your trying to make it to hard?
if left is -1 to 0, and right is 0 to 1, and assuming the joystick cannot be both left and right at the same time - that is to say, left will be 0 if right is > 0 and visa versa, then simply add them together.
horizontal = left + right // will always yield values between -1 and 1.