- Home /
Have enemy move in 8 way direction 3D
So I'm working on a Zombie wave spawning game and want the enemies to move in an "8 way direction rotation" (basically moving in multiples of 45 degrees). So far I can get the enemies to move towards the player, however I can't figure out the proper way to have them rotate in the proper degree direction.
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
Debug.Log(moveHorizontal + " " + moveVertical);
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
if (movement != Vector3.zero)
transform.rotation = Quaternion.LookRotation(movement);
transform.Translate(movement * speed * Time.deltaTime, Space.World);
This code works fine and proper for the player, however I can't find a way to I guess "convert it" without using inputs for the enemies. Any help is greatly appreciated. Thanks guys!
Comment