This post has been wikified, any user with enough reputation can edit it.
Question by
maksymdev · Jul 25, 2016 at 12:17 PM ·
player2d-platformerenemyfollow
Move enemy towards player if enemy is in Camera bounds?
Hey, it is my first question here and I did some research before asking, but if I missed something I am so sorry. I will get to the point : I have script that makes Enemy move towards my Player (it is 2D platformer). Enemy move if distance between Player and object is less than max dist. but if I reach higher value with my Player than max dist Enemy stops following.
if (Vector2.Distance(transform.position, Player.transform.position) <= 10.0f)
{
Vector2 enemyVelocity = new Vector2((transform.position.x - Player.transform.position.x) * Speed, 0);
rgBody2d.velocity = -enemyVelocity;
anim.SetFloat("Speed", enemyVelocity.magnitude);
}
How can I make follow my player if it shows in Camera and do not stop until it reaches the Player? I would be thankful even for some links so I can manage with this by myself.
Comment