Can anyone please explain how to set up a proper waypoint system? I want my enemy to patrol along a given waypoint path and if I get within range of the enemy it will attack me. If I run out of range of the enemy, it should go back to it's patrol, or at least the nearest waypoint.
I've been playing with example projects and scripts from all over the place and still no luck. Any help is greatly appreciated. Thank you!
asked Mar 09 '11 at 03:28 PM
Do you want the enemy to chase after the player when the player is in range or just stop moving along the path and start shooting? Implementing path following AI is easy. Having enemy AI chase the player intelligently is less so.
Update: The simplest way I've found to make a path following AI requires three parts: an enemy object, a parent path object, and individual path node objects.
The enemy has a public game object that you can assign in the editor to the path object you want it to follow, and a function that moves it towards a given position. In the update function of the enemy have it move toward the position of a node in the list, and upon reaching it have it move to the next node.
The parent path object needs a public list that will contain all nodes in the path and a function that sorts the list based on an int inside of the node class.
The node object needs a public int (as mentioned above) that determines its order in the path. It also needs a function that adds it to the parent object's list of nodes to be called on start.
I realize that's a complicated explanation. I'm tempted to just make a sample project and upload it. I dunno, let me know how it goes.
Create an empty gameobject, name it waypoint, duplicate it, drag it and make it a child of the waypoint. Position them where ever. Ta da. You got your waypoint.
For the code however.. I'd do something like this..
Now you got your guy going from 1 waypoint to the other..
answered Apr 15 '12 at 11:21 PM
If it says: "Assets/Scripts/Waypoints.js(38,5): BCE0005: Unknown identifier: 'MoveTowards'."
add this to your script
answered Jun 18 '12 at 01:55 PM