Hi, I’m not certain how to make the enemy move a bit faster over time when the enemy is on your line of sight (LOS). And gradually return to normal speed when it’s not in LOS.
Also make the enemy stop all movement you “player” isn’t in the enemy’s LOS after a few seconds.
EDIT
My bad, I thought you were having a bug. Titles are so misleading lol (that or I need more sleep!). What you want to have is a sight range (based on Vector3.Distance) or an invisible collider in front of the player that will detect if an enemy is in front. The collider then has a script that will call a function from the enemy to increase the speed of that particular enemy inside the ‘sight range’.
If you’re going with the collider, here’s what you would need:
void OnTriggerEnter(Collider other)
{
if(other.tag == "Enemy")
{
other.GetComponent<EnemyAI>().SpeedBoost(); // Function will deal with increase speed and how long it will be
}
}
The above code will deal with when the Enemy enters the sight range.
void OnTriggerExit(Collider other)
{
if(other.tag == "Enemy")
{
other.GetComponent<EnemyAI>().RemoveSpeedBoost(); // Function will deal with removing speed
}
}
The above code deals with when the Enemy leaves the sight range.