I’ve currently setup a 4 direction attack + block system in my game, which is a first person melee game. Basically I compare the x and y movements of the mouse with their absolute value, which gives me 4 directions. Any ideas on how to expand this into 8 directions?
Divide (integer) through (360° / direction count) or (2PI / direction count) Generally Speaking dividing through size of one circle segment
Now you have an integer reprensenting the segment you are in, which i would cast to an ENUM (note the enum needs to be in correct order for that to work)
Compare abs of X and Y to determine the mouse direction (X or Y), sends a bool to a branch.
Compare the original axis value to get the respective direction.
Then branch again (twice) to compare whether or not the axis is > or < to get the direction.
I’ve decided to go with a 5 direction combat system instead after some thought.
How would you compare this method with the method you described? I’ve only just implemented mine and it seems a little dodgy, but I need to check values and whatnot.
Scratch that - sorta.
Now, instead of comparing the x and y axis at the beginning, I simply get the Y axis, and compare whether it’s going left or right. This gives me six axis to work with and seems to work great!