Exemple #1
0
    public BehaviourTreeConstructor InvertedCondition(string name, Func <float, bool> function)
    {
        //Debug.Log("Add the condition : " + name);
        BehaviourTreeConstructor Result = Do(name, t => function(t) ? BehaviourTreeStatus.Failed : BehaviourTreeStatus.Succes);

        //Debug.Log("The Action : " + name + " return : " + Result);
        return(Result);
    }
Exemple #2
0
    private void Start()
    {
        GameManager GM = GameManager.instance;

        target = GM.Player.transform;

        rb      = GetComponent <Rigidbody>();
        seek    = new Seek(transform, target, rb, MaxSpeed, 1, 0, new Vector3(-10, -10, 0));
        flee    = new Flee(transform, target, rb, MaxSpeed, 1);
        arrival = new Arrival(transform, target, rb, MaxSpeed, 0.5f, SlowingDistance, MaxDistanceFromTarget);
        arrival.SetOffset(TargetOffset);
        pursuite          = new Pursuite(transform, target, rb, MaxSpeed, 1, MaxDistanceFromTarget);
        obstacleAvoidance = new ObstacleAvoidance(transform, target, rb, MaxSpeed, 1f, MAXAHEAD, MaxAvoidanceForce, colliders);
        separation        = new Separation(transform, target, rb, MaxSpeed, 1.0f, AvoidTargetDistance);
        wanders           = new Wanders(transform, target, rb, MaxSpeed, 1.0f, RadiusWanders, LittleRadiusWanders);

        BTconstructor = new BehaviourTreeConstructor();


        //BTCloseTarget = new BehaviourTreeConstructor();

        //BTFarTarget = new BehaviourTreeConstructor();

        //BTFarTarget.Condition("DistanceTest", IsTargetOutOfRange).Do("Seek", AddSeek).End().Build();

        tree = BTconstructor.Sequence("Root").Sequence("BasicSequence")
               .Selector("Test")
               .Selector("TRackBehaviour")
               .Sequence("InTargetRange")

               .Condition("IsInAttackRange ?", IsTargetInAttackRange)
               .Selector("PlayerInMove")

               .Sequence("Check Player is in move")

               .InvertedCondition("IsPlayerInMove", TargetIsMoving)
               .Do("Wander", AddWanders)
               .Do("LookForward", LookForward)
               .End()
               .Sequence("In case of player was not in move")

               .Do("Arrival", AddArrival)
               .Do("LookForward", LookOnTarget)
               .End()
               .End()

               .End()


               .Sequence("InDetectionRange")

               .Condition("IsInDetectionRange", IsTargetInDetectionRange)
               .Do("Seek", AddSeek)
               .Do("LookForward", LookForward)

               .End()

               .End()

               .End()

               .Do("ObstacleAvoidance", AddObstaclAvoidance)
               .End()

               .Build();

        //behaviorTreeStearingLeaf = new BehaviorTreeStearingLeaf(seek.GetSteering);
        //DistanceCheckPlayer = new ConditionNode(IsTargetInRange,behaviorTreeStearingLeaf);
        //root = new BehaviourTreeRoot(DistanceCheckPlayer);

        //root.Init(root);
    }