Hi, i have a problem and i hope the unity community can help me.
I want to make an artificial intiligence script but i don’t know how to do it.
The AI will try to kill my player and if there is a cube wich blocks him, the AI must destroy it and hide him self if is it possible or roll away a distance from the bomb.
Thanks in advance
(PS: sorry for my english i’m french:smile:)
i would check this out: https://www.assetstore.unity3d.com/#/content/6563
it looks pretty powerful and is free, but probably takes some getting used to
the basic approach would be something like this pseudo code
while(true) {
// get all objects in front of agent
objectsHit = Physics.RaycastAll( agentPosition, agentLookAhead )
// if the player is not somewhere in front of agent
if( objectsHit !contain Player) {
// move agent around and check again
continue;
}
// the player is in front of agent, leave the loop
break;
}
// get the nearest object in front of agent
lookAtObject = Physics.Raycast ( agentPosition, agentLookAhead )
if( lookAtObject is Player ) {
// agent is looking directly at player, go kill him
}
else if( lookAtObject is cube ){
// a cube is blocking the way to player, go bomb it
}
else {
// something else is blocking the way
}
Thank you
Hi, thank you for answering to my quetion but i have another one ^^. How my ennemy can roll away from the bomb and how can my ennemy can find a safe place.
Thanks a lot for your help and your time.
(PS can you allow private message please?)
You want to read up on finite state machines; literally any action you describe will come down to a trigger/event, new state, new target, pathing.
(ex. detect nearby bomb via trigger, new state is retreat, new target is closest safe zone, move to safe zone, reach safe zone: new state is search).
This guy (link below) does some rudimentary state machine AI. For the pathing I’d recommend A*, or any of the numerous AI libraries for free on the asset store; alternatively you could look into behavior trees, but I think state machine will be simpler and sufficient for your game.