|
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! Shawn
(comments are locked)
|
|
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. Lets just go with AI moving from waypoint to waypoint. I don't even know how to create a waypoint. What scripts are involved? Please help. I appreciate it! Thank you for your repsonse. Shawn
Mar 09 '11 at 11:13 PM
shawnkilian
Alright I updated my post with the logic for a path following system. A waypoint in this case is just a cube object or something with a script attached.
Mar 10 '11 at 07:28 PM
Tuck
(comments are locked)
|
|
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.. It doesnt work! it says: "Assets/Scripts/Waypoints.js(38,5): BCE0005: Unknown identifier: 'MoveTowards'."
Jun 03 '12 at 05:57 PM
Estevominador
where should I attach this script? and... is the gameobject that you mentioned is the enemy? or just the waypoint?
Feb 24 at 11:31 AM
chiako
(comments are locked)
|
|
If it says: "Assets/Scripts/Waypoints.js(38,5): BCE0005: Unknown identifier: 'MoveTowards'." add this to your script
(comments are locked)
|
