8 Axis Movement

I am making a sprite movement script and I wanted to know, it was possible to have 8 axis movement like up, up right, right you get the point.

Of course it is!(That’s all you want right? :p)

you can basically transform the axis into direction vector.

[System.Flags]
enum Direction
{
  None = 0x0,
  Left,
  Right,
  Up,
  Down,
  UpLeft = Up | Left,
  UpRight = Up | Right,
  DownLeft =  Down | Left,
  DownRight = Down | Right
};

var dx = Input.GetAxisRaw("Horizontal");
var dy = Input.GetAxisRaw("Vertical");
var direction = Direction.None;

if(dx > 0)
  direction |= Direction.Right;
else if(dx < 0)
  direction |= Direction.Left

if(dy > 0)
  direction |= Direction.Up
else if(dy < 0)
  direction |= Direction.Down

:open_mouth: NICE MAN!!!, Thanks. btw how do you put the code in the little grey box.

When you reply, at the bottom left click “Go Advanced”.
Then choose the code tag(with “#” symbol) from the toolbox. write your codes inside it :slight_smile:

thank you