Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemy AI ignores the distance from the player

$
0
0
Hi, I'm making a 2D platform and I'd like the enemy to follow the player only within a fixed range. When using this script tho it follow the player regardless of the distance. Could you help me out? void distanceFromPlayer() { float dist = Vector3.Distance(player.transform.position, transform.position); } void getToPlayer() { if (dist <= 10.0f) { Vector3 dir = (player.transform.position - transform.position).normalized; dir.y = 0.0f; //not changing y dir transform.Translate(dir * _speed * Time.deltaTime); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles