Last active
November 11, 2021 12:16
-
-
Save Bishwas-py/4497d510f1904b9b2e96884e892e5701 to your computer and use it in GitHub Desktop.
Enemy Follow Player Unity 2D
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
IEnumerator GiveJumpingJerks() | |
{ | |
while (isPlayerAlive) | |
{ | |
yield return new WaitForSeconds(Random.Range(1, 3)); | |
try | |
{ | |
var playerToTriangle = (player.transform.position - transform.position); | |
if (allowJumping) | |
{ | |
myBody.AddForce(new Vector2( | |
playerToTriangle.normalized.x * Random.Range(playerToTriangle.magnitude - 5, | |
playerToTriangle.magnitude + 5), | |
Random.Range(1, jumpingJerkRange)), ForceMode2D.Impulse); | |
myBody.rotation += rotationSpeed * 3; | |
} | |
allowJumping = false; | |
} | |
catch(MissingReferenceException fException) | |
{ | |
isPlayerAlive = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment