So i have a code for joystick for my fps game i took from the joystick asset pack. It works great. I set it up with alot of if else statements for what it needs to do when the input i get from moving the joystick is more than 0. If the input.y is more than 0, it should move forward, if its less than 0, it should move backwards. If input.x is more than 0, it should move right, if its less than 0 it should move left. But the problem is, if i try to move my joystick right or left to move my character right or left, there still comes some input.y which is not at 0 ( as it should, cuz when i move joystick it doesnt go directly right or left, it might go in up and down (input.y) territory too). And as in my if else statements, my first 2 statements are for forward and backward, and when i try to move it right or left, it gets some input.y and moves the character forward or backward. It never goes to the last if else statements where its supposed to more right or left. So, i wanted something like this, but i dont know the logic to write it: i want make an area subtended by an angle from 0,0 point. There should be 4 areas, each of 90 degrees, like the below pic. If my joystick handle is moving in the area of x, the character should go forward, if its in the down, it should go back, if its in right, it should go right and if its in left, it should go left. Can someone help me write the program to it. Im new to unity so i would appreciate any help! Thankyou.
Usually in a game up/down is independent of right/left so you wouldn’t say “up/down else right/left”. Make them separate if/else statements.