How can you realize the movement of monsters in Diablo. Namely, only on 8 sides (vertically, horizontally and diagonally) on mobile devices, where the control with the help of a joystick on the screen. The game is isometric, there are monster sprites on 8 sides. And that's the problem. The monster moves behind the character, for example, downwards, then the character shifts diagonally and until the deflection angle is sufficient, the monster will be directed downwards, and it will already be moving with an offset diagonal. And it is necessary as in Diablo, to strictly on 8 sides. For clarity, this is https://youtu.be/0aQnRBAMVqE
Monster Motion Script:
public class EnemyControl : MonoBehaviour { private Animator anim; // Use this for initialization void Start () { anim = this.GetComponent<Animator> (); } // Update is called once per frame void Update () { float input_x = GetComponent<Rigidbody2D>().velocity.x; float input_y = GetComponent<Rigidbody2D>().velocity.y; bool walkingEnemy = (Mathf.Abs(input_x) + Mathf.Abs(input_y)) > 0; anim.SetBool("walkingEnemy", walkingEnemy); if (walkingEnemy) { anim.SetFloat("x", input_x); anim.SetFloat("y", input_y); transform.position+=new Vector3(input_x, input_y, 0).normalized*Time.deltaTime; } } }