- Home /
Creating a AI controller
I'm trying to create a simple AI controller that uses waypoints and 5 animations: Idle, Walk, Shoot, Take Damage and Death. I want the AI to travel to a way point then stop for a certain time then begin travelling to the next way point. I'll add the rest of the script in the comments.
Okay... But what's your problem? What issue do you want to solve?
Answer by Nocktion · Apr 03, 2019 at 04:56 PM
Okay okay. First of all if you haven't got any kind of barriers between two way points then you shouldn't have to use na navmeshes. If this is the case then it's pretty simple just rotate your AI character in the direction of the waypoint and using the walk animation travel the character to the point. Then create a random value e. G. int break = Random.Range(5, 15);, start the idle animation and use a coroutine to wait 'break' seconds before starting movement animation again. Meanwhile in the update function get an overlap sphere with the range of sight of the AI and check if there are any enemies in the array if yes then stop the walk animation, set your enemy as a target, rotate the character towards the enemy and trigger the shoot animation. If there are multiple enemies in range then do the same except you will have to compare their distance first then use the closest one as target. And lastly if the health of you character hits zero, trigger the death animation. The case is almost the same with a navmesh except you will have to use the waypoints given by the navmeshaicontroller or whatever it is called (sorry I don't remember it's exact name). So that's it. If something is unclear or you need some code, then just comment under my answer. Happy coding!
Okay so I've tried to get the character to patrol but it won't go towards a way point. It just stays within the idle state, however when it does reach the waypoint the rotation starts to glitch out. Do you have any code handy that I could use as a template? I'll add a screenshot of my code when I can. Thanks
Your answer
Follow this Question
Related Questions
Horde of NavMeshAgents - stops to recalculate path. 4 Answers
Find the closest point of an Invalid or Partial path 0 Answers
AI pathfinding waypoints 1 Answer
How to build a custom shape NavMesh Area 1 Answer
Navmesh agent stuck on partial path 0 Answers