hello , im looking for help with which way the joystick is going for example , top , top right , right , bottom right , ect… , it is for my animations as each one is linked to it , i know it requires checking the horizontal + verticle input , but not sure how i would check for example top would be -0.35 < joystick.Horizontal && 0.35 > joystick.Horizontal && joystick.Vertical > 0.93 && joystick.Vertical > 0.93 , but this is when joystick is fully up , but if pushed up a tiny bit it wouldnt register as top
Two problems:
Don’t consider any input until the total magnitude of the X/Y vector is greater than a certain amount
Use Mathf.Abs() to decide if X or Y is the bigger deflection axis.
Combining it:
// THIS IS NOT CODE, it is python-ish pseudocode:
if XY.magnitude > threshhold:
if X > Y:
if X < 0: left
if X > 0: right
if Y > X:
if Y < 0: down
if Y > 0: up
1 Like
Convert your direction vector to a 0-359 degree angle, then divide that by 45 and floor it to get a value from 0-7 mapping to your cardinal/ordinal directions.
1 Like
could you check the object to see what angle he is moving at? if so how would that be done?
edit : nevermind got it
float angle = Mathf.Atan2(joystick.Vertical, joystick.Horizontal) * Mathf.Rad2Deg;