I have managed to make my AI follow me around as soon as he sees me but he doesn’t stop when I get out of sight. I also want the enemy (AI) walk around randomly before he sees me and start walking around randomly again when I get out of Sight. Everything is in a maze so the enemy needs to know where the walls are so he doesn’t walk trough them.
At the moment I’m using the behavior tree system of RAIN indie to let the AI follow the player.
Here’s what I’ve got so far:
<behaviortree name="Enemy" precondition="" repeatuntil="" debug="False"><sequencer name="root" precondition="" repeatuntil="" debug="True"><detect name="detect 241" precondition="" repeatuntil="" debug="True" sensor="sight" aspect="target" variable="playerpos" /><move name="move 2403" precondition="" repeatuntil="" debug="True" movetarget="playerpos" movespeed="-1" looktarget="playerpos" lookspeed="-1" animation="" animationlayer="0" animationwrapmode="default" animationbasespeed="2" /></sequencer><variable name="CanSee" initialvalue="0" /></behaviortree>
I would also apreciate if anyone could tell me how to do this without using an asset and just a script.
Thanks for your Help.
I’m trying to do this now with a script. It’s like that:
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
private GameObject Player;
private bool CanSee = false;
void update()
{ if(CanSee=true)
{
follow();
}
else{
random();
}
}
private void follow()
{ //lets the enemy follow the player
RAIN.Path.MoveLookTarget.SaveLastPosition(Player);
}
private void random()
{ //lets the enemy move randomly
}
}
Of course it knows now when it can see the player. Now I’m trying to let it walk to the player.
EDIT: I’ve found now a class called RAIN.Motion.Instantaneous.SB_Wander it should let an object wander around. But I don’t know how to use this in a script. Can someone help me?