AI Problem.
Hello guys,
I'am trying to make a simple sneak AI, when you press "C" the VisionDistance of the enemy decrease to 3, it works just when I have 1 enemy in the scene, but when I have more than one enemy, this just work with one of them. What i'am doing wrong ?
[UPDATE] Hello, I realized that it only ocurs when i try to change the var VisionDistance(EnemyScript) inside the PlayerScript, why this ?
PlayerScript:
bool Sneak;
//Those are all the lines that change something in the EnemyScript
if(Input.GetKeyDown (KeyCode.C))
{
Sneak = !Sneak
if(Sneak == true)
{
EnemyScript.VisionDistance = 3;
}
else
{
EnemyScript.VisionDistance = 5;
}
}
EnemyScript:
float VisionDistance;
// I calculate the distance betwen Enemy and Player, if the Distance < VisionDistance I send a Ray in Player Direction, if hit = Player the Enemy Attack.
The way it works:
PlayerScript:
bool LessVision;
//When Press C LessVision = true;
//When Press C and LessVision = true --- LessVision = false
ZombieScript:
if (PlayerScript.LessVision == true)
{
MaxDistance = 3;
}
else
{
MaxDistance = 5;
}
Sorry for my english. Thank You.
Hello, I realized that it only ocurs when i try to change the var VisionDistance(EnemyScript) inside the PlayerScript, why this ?
Thanks
it is not clear how do you calculate the distance between Enemy and Player but i think you use bool Sneak;
to deter$$anonymous$$e if there is a snake in the scene . will bad idea ins$$anonymous$$d use FindGameObjectsWithTag ("") :
GameObject [] Sneaks;
void Update(){
Sneaks = GameObject.FindGameObjectsWithTag ("Snake");
}
this way will find all game objects tagged Snake & store them in array
Can you please provide your code? Without it we cannot see what the problem might be.
Your answer
Follow this Question
Related Questions
Need help with physics base enemy AI movement 1 Answer
Disable a Function when another and active (javascript AI) 1 Answer
Raycast Enemy AI shooting script 1 Answer
Flying ship AI 0 Answers
Interesting Enemy AI issue 2 Answers