- Home /
How should I calculate an 8-directional animation based on 360 degree rotation around the player using raycast?
I'm using a 2D sprite with 8-directions of movement and animation in an isometric 3D game. In order to have 360 degrees of mouse movement (to shoot and dash to mouse position). The animation system is using Horizontal and Vertical axes to create values between [-1, -1] and [1, 1] and I'm storing values of the last axial position to use for Idle.
I'm attempting to implement a ray-cast system for this to get an effect similar to Hyper Light Drifter where the weapon rotates freely within a range and at the transition points the player animation changes to face the right direction. See video for reference: here.
My question is how should I go about implementing this using ray-casting? See the picture for more detail.
I know that I could do it with mathematics, Trigonometry if I remember correctly. Alternatively I could have a plane cut into chunks but this feels too hacky and un-efficient.
If there is an alternative way better than my thoughts, feel free to add that too.