Last active
September 10, 2020 21:42
-
-
Save dcbriccetti/451aeca04f11bf9be5046ebbdba052c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Vector3 EnemyMovement(Transform closestUnit, Transform enemy) { | |
Vector3 enemyToUnit = closestUnit.position - enemy.position; | |
int maxManhattanDistancePerMove = 3; | |
int xDirection = Math.Sign(enemyToUnit.x); | |
int zDirection = Math.Sign(enemyToUnit.z); | |
int xSteps = (int) Math.Min(maxManhattanDistancePerMove, Math.Abs(enemyToUnit.x)); | |
int stepsLeft = maxManhattanDistancePerMove - xSteps; | |
int zSteps = (int) Math.Min(stepsLeft, Math.Abs(enemyToUnit.z)); | |
int dx = xDirection * xSteps; | |
int dz = zDirection * zSteps; | |
return new Vector3(dx, 0, dz); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Surely there’s some mathy way to avoid all the sign and abs business.