I'm working on a game with z game editor and I wanted to create a model that has 8 directions of animation depending on it's movements, so the most obvious comparison to what I want to implement would be the ghosts from a game like the arcade version of gauntlet,

the way I thought of doing this was by having a variable connected to different states, each state playing a different animation.
Unfortunately, even after some years of working on getting my head around basic trigonometric functions (the equivalent of year 10 maths)
I still find it hard to visualize the correct formulas to get the Sin (opposite over hypotenuse), cos (adjacent over hypotenuse) and tan (opposite over adjacent),in relation to the velocity of an object.
I really want to understand this stuff, since it actually quite basic, and it would mean that I could make games faster.
Anyway,
so, I wrote this code which doesn't appear to work, and im not sure why.
This is the code:
Dir=round(atan2(currentmodel.velocity.x,currentmodel.velocity.z)/PI*2)/2/8);
what I was hoping for it to do was to spit out 8 intergers, depending on the direction of my models,
for some reason it's not doing that.
Does anyone have any ideas on how I can solve this problem?
