- Home /
How do you create an AI that works like this ?
I'm referring to the game 'Gesundheit' - Gameplay Link. The game is very sprite heavy. How is it possible to create Navigation Meshes for a game like that ? Also, how do you create a constant field of view check for the monsters, to check if the player is currently visible or not ? Does such a behavior require pathfinding algorithms, or is it possible to plain code them ? How is it possible to code a behavior that if the player escapes out of the sight of the monster, that the monster will give up chasing the player and go back to rest, like in the gameplay video ?
I apologize if I'm asking too many questions inside a single one, though I feel that there is a possible singular answer to it. It would be great if you could point out some useful resources that I could refer to, to achieve this. Also, I do not wish to use other plugins/assets from the Asset Store.
Thanks for taking the time to read this.
Also, how do you create a constant field of view check for the monsters, to check if the player is currently visible or not ? Does such a behavior require pathfinding algorithms, or is it possible to plain code them ? How is it possible to code a behavior that if the player escapes out of the sight of the monster, that the monster will give up chasing the player and go back to rest, like in the gameplay video ?
Imo, you migh want to take a look at raycast to see if either player or some object is near, then use a simple path-finding to go toward that place.
Good luck!
Answer by Cherno · Aug 18, 2014 at 01:13 AM
1) How is it possible to create Navigation Meshes for a game like that ?
I recommend the "Astar Pathfinding Project". The basic version is free and very powerful. If you don't want to use any resources from the Asset Store, well, good luck to you, and use Unity's own NavMesh feature.
2) Also, how do you create a constant field of view check for the monsters, to check if the player is currently visible or not?
var fov : float = 60.0f;
var maxDistance : float = 10.0f;
var blockLayerMask : LayerMask;
function CheckLoSHitBox (target : GameObject) : boolean
{
if (Vector3.Angle(target.transform.position - transform.position, transform.forward) <= fov)
{
if(Vector3.Distance(transform.position, target.transform.position) <= maxDistance)
{
var hit : RaycastHit;
if(Physics.Linecast(transform.position, target.transform.position, hit, blockLayerMask) == false)
{
Debug.DrawLine (transform.position, target.transform.position, Color.white);
return true;
//hitting the actual target is not needed to "see" it! if the ray is not blocked by obstacles or ground, that's enough!
}
}
}
Debug.DrawLine (transform.position, target.transform.position, Color.red);
return false;
}
3) Does such a behavior require pathfinding algorithms, or is it possible to plain code them ?
What kind of behavior do you mean? You can check if the monsters see the player, and then give their pathfinding script the player's position as a target position, and make them start moving toward him or her.
4) Easy; if the monster is no longer seeing the player, it just returns to it's starting position or maybe roam around randomly. You just set a boolean "seeingPlayer" to true if the FoV-check above returns true, and to false if it doesn't. It's enough to check every second or so, you don'T have to call it every frame.
Thanks for replying to this. You pretty much answered all of my questions. I was assu$$anonymous$$g that A* Pathfinding was a paid asset. I'll look into the free version. Thanks yet again !
Your answer
Follow this Question
Related Questions
Navmesh agent stuck on partial path 0 Answers
How to build a custom shape NavMesh Area 1 Answer
using a Mesh Volume for AI 1 Answer
Make a flying enemy ? 0 Answers
How to do AI pathfinding on trees and other vertical surfaces? 0 Answers