- Home /
Could use some help on making my runaway/chase/follow/patrol script cooperate with each other
Hello! I have a game where you are chased by a security guard but if you've bought the dog companion, the dog will chase away the security guard until he is far enough away that his code doesn't make him want to follow you anymore. I have two scripts, one for the dog and one for the security guard. Here they are: security guard: https://pastebin.com/8ikCsryg dog: https://pastebin.com/rEpLbFd5
My guess is my logic with all the bools is getting messed up and could use some other eyes on it. What's happening now is the security guard never 'notices' the dog, he just follows the player and the dog follows him //It's very janky and I'd love some help!
Answer by DCordoba · Jan 27, 2019 at 12:43 AM
first, congrats to make a code so clean, is very nice to read seriously.
probably you already got the problem but, here we go
on guard script, you never set runAway
as true, so, the guard dont know the fear xd
so edit the part of the follow algorithm, lines 29 to 37:
if (follow)
{
cop.SetDestination(Player.transform.position);
eye.SetActive(true);
if(dist <= 1.05f)
{
sendToJail();
}
//set the distance to start runing
if(dogDist<3f){
follow = false;
runAway = true;
patrol = false;
}
}
also consider use (doggy.transform.position- cop.transform.position).sqrMagnitude this make computation fast, because you need calculate it on update function, but remember you need to set all the constats (the minimium distance to change behavior) squared, to keep the same state.
Your answer
Follow this Question
Related Questions
Scavenger Hunt List Bools Question 1 Answer
c# Ignoring conditional statement? 1 Answer
How Do I check if a Bool was True a few moments ago 2 Answers
C# Boolean Constantly Changing 1 Answer
What does this mean? 1 Answer