// Use this for initialization void Start() { MoveLocation = transform.position; //CREATING OUR ZOMBIE BEHAVIOUR TREE //Get reference to Zombie Blackboard ZombieBB bb = GetComponent <ZombieBB>(); //Create our root selector Selector rootChild = new Selector(bb); // selectors will execute it's children 1 by 1 until one of them succeeds BTRootNode = rootChild; //Flee Sequence CompositeNode fleeSequence = new Sequence(bb); // The sequence of actions to take when Fleeing FleeDecorator fleeRoot = new FleeDecorator(fleeSequence, bb); // defines the condition required to enter the flee sequence (see FleeDecorator) fleeSequence.AddChild(new CalculateFleeLocation(bb)); // calculate a destination to flee to (just random atm) fleeSequence.AddChild(new ZombieMoveTo(bb, this)); // move to the calculated destination fleeSequence.AddChild(new ZombieWaitTillAtLocation(bb, this)); // wait till we reached destination fleeSequence.AddChild(new ZombieStopMovement(bb, this)); // stop movement fleeSequence.AddChild(new DelayNode(bb, 2.0f)); // wait for 2 seconds //Fight sequence CompositeNode FightSequence = new Sequence(bb); // The sequence of actions to take when Fighting FightDecorator fightRoot = new FightDecorator(FightSequence, bb); //defines the condition required to enter the fight sequence(see FightDecorator) //Defining a sequence for when the Zombie is to do it's combo attack, this is a nested within our FightSequence Sequence ZombieCombo = new Sequence(bb); ZombieCombo.AddChild(new ZombieClawPlayer(bb)); // claw the player ZombieCombo.AddChild(new DelayNode(bb, 0.8f)); // wait for 0.8 seconds ZombieCombo.AddChild(new ZombieBitePlayer(bb)); // bite the player ZombieCombo.AddChild(new DelayNode(bb, 1.5f)); // wait for 1.5 seconds FightSequence.AddChild(new ZombieMoveToPlayer(bb, this)); // constantly move to player until within range FightSequence.AddChild(new ZombieStopMovement(bb, this)); // stop movement FightSequence.AddChild(ZombieCombo); // perform combo sequence //Adding to root selector rootChild.AddChild(fleeRoot); rootChild.AddChild(fightRoot); //Execute our BT every 0.1 seconds InvokeRepeating("ExecuteBT", 0.1f, 0.1f); }
public FleeDecorator(BTNode WrappedNode, Blackboard bb) : base(WrappedNode, bb) { zBB = (ZombieBB)bb; }
public ZombieMoveToPlayer(Blackboard bb, Zombie zombay) : base(bb) { zBB = (ZombieBB)bb; zombieRef = zombay; }
public ZombieWaitTillAtLocation(Blackboard bb, Zombie zombay) : base(bb) { zBB = (ZombieBB)bb; zombieRef = zombay; }
public CalculateFleeLocation(Blackboard bb) : base(bb) { zBB = (ZombieBB)bb; }