protected override void HandleMovement() { var pos = transform.position; var x = pos.x; var y = pos.y; if (Math.Abs(x - Mathf.Floor(x)) < 0.1 && Math.Abs(y - Mathf.Floor(y)) < 0.1) { if (RandomChange()) { HandleChangeDirection(); } else { Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction); } } else { Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction); } }
private void HandleChangeDirection() { Direction = ChooseRandomExceptCertainDirection(Direction); MoveToCenterOfTheCell(); Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction); }
protected override void HandleMovement() { Rigidbody2d.MovePosition(Rigidbody2d.position + Speed * Time.deltaTime * Direction); }