Hi, so far my enemy is walking towards the player when the player is in a certain range of the enemy. When the enemy reaches meleeAttackrange it attacks and when the player manages to get out of the enemies deception radius - the enemy runs back to its spawn point. Here is where I have a problem.
So far the enemy chooses the shortest way back to its spawn, which is quiet a problem since my level is a dungeon. The enemy runs against the closest wall …
My idea was to send the enemy back to its spawnpoint using waypoints. I have placed some lights in my map on strategic points and attached an empty gameobject (waypoints) to those points. The plan is to make the enemy search for the closest waypoint and walk to that waypoint and then decide wether it needs another waypoint to reach the spawnpoint or wether it can reach the spawnpoint without walking to another waypoint.
I am still thinking about this problem .
So far I have the following idea:
create a function called findwaypoint.
in this function i am checking the distance of the enemy.position to the waypoint position closest to the enemy. If walking to this waypoint shortens the distance between the enemy and the spawnpoint - walk() is called and then check again until the enemy reaches the spawn point.
There is a flaw in my logic. and i still cant figure out how to manage…
the shortest distance from the enemy to the spawn is the straight line and walking to the right waypoint might enlengthen this distance. Further, right now this idea may choose a waypoint that leads to nowhere…
unfortunately i am not sure how to make a walk home using waypoint function.
Does someone have an idea?