Exemple #1
0
 void Update()
 {
     actionNew.activated = false;
     actionOld           = actionNew;
     actionNew           = root.MakeDecision() as Action;
     if (actionNew == null)
     {
         actionNew = actionOld;
     }
     actionNew.activated = true;
 }
Exemple #2
0
    public State GetState()
    {
        ActionState action;

        action = root.MakeDecision() as ActionState;
        return(action.state);
    }
Exemple #3
0
 public override DecisionTreeNode MakeDecision()
 {
     if (isLoaded)
     {
         return(root.MakeDecision());
     }
     return(null);
 }
Exemple #4
0
    private void Update()
    {
        oldAction = newAction;
        newAction = root.MakeDecision(agent) as AgentAction;
        if (newAction == null)
        {
            newAction = oldAction;
        }

        newAction.Execute();
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        bool bWantToFire   = false;
        bool bWantToShield = false;


        // This would be better to traverse and set based on what each node is. For now, this is good enough if gross.
        ((Decision)dTree).testData = mEffector.ShieldStatus;
        ((ShotApproachingDecision)(((Decision)dTree).trueNode)).testData = CheckForNearestShellDistance();
        ((IsGunReadyDecision)(((ShotApproachingDecision)(((Decision)dTree).trueNode)).trueNode)).testData = mEffector.IsGunReady();
        ((FacingEnemyDecision)(((IsGunReadyDecision)(((ShotApproachingDecision)(((Decision)dTree).trueNode)).trueNode)).trueNode)).testData = AngleToTarget();

        ((Decision)(((Decision)dTree).falseNode)).testData = mEffector.ShieldStatus;
        ((ShotApproachingDecision)(((Decision)(((Decision)dTree).falseNode)).trueNode)).testData = CheckForNearestShellDistance();
        ((IsGunReadyDecision)(((Decision)(((Decision)dTree).falseNode)).falseNode)).testData     = mEffector.IsGunReady();
        ((FacingEnemyDecision)((IsGunReadyDecision)(((Decision)(((Decision)dTree).falseNode)).falseNode)).trueNode).testData = AngleToTarget();

        ((IsGunReadyDecision)(((ShotApproachingDecision)(((Decision)(((Decision)dTree).falseNode)).trueNode)).falseNode)).testData = mEffector.IsGunReady();
        ((FacingEnemyDecision)(((IsGunReadyDecision)(((ShotApproachingDecision)(((Decision)(((Decision)dTree).falseNode)).trueNode)).falseNode)).trueNode)).testData = AngleToTarget();

        DecisionTreeNode node = dTree.MakeDecision();

        if (node is ShieldOnAction)
        {
            bWantToShield = true;
        }
        if (node is ShieldOffAction)
        {
            bWantToShield = false; // Seems to be a bug here, shield isn't wanting to turn off. *Might be a logic issue with toggling a button to enable/disable stuff?)
        }
        if (node is ShootGunAction)
        {
            bWantToFire = true;
        }

        steering = new SteeringOutput();

        // Blend Steering
        //steering += Seek.GetSteering(target._static.position, self._static.position, tank.maxSpeed).Weight(1.0f);
        sm.Update();
        //steering += Flee.GetSteering(target._static.position, self._static.position, tank.maxSpeed).Weight(1.0f);
        //steering += AlignToTarget2.GetSteering(target._static.position, self._static.position, self._static.orientation).Weight(1.0f);
        Rigidbody srb = tank.GetComponentInChildren <Rigidbody>();
        //steering.Crop();
        float angle = Vector3.SignedAngle(steering.velocity.normalized, srb.transform.forward, transform.up);

        //Horizontal = Input.GetAxisRaw("Horizontal");
        //Vertical = Input.GetAxisRaw("Vertical");

        ResetMovement();

        if (steering.velocity.magnitude > 0)
        {
            if (angle > -90 && angle < 90)
            {
                MoveForward = true;
            }
            if (angle < -90 || angle > 90)
            {
                MoveBackward = true;
            }
            if (angle > 0)
            {
                TurnLeft = true;
            }
            if (angle < 0)
            {
                TurnRight = true;
            }
        }
        if (steering.rotation < 0)
        {
            TurnLeft = true;
        }
        if (steering.rotation > 0)
        {
            TurnRight = true;
        }

        // Disable movement direction if inputs are contradicting each other.
        if (TurnLeft && TurnRight)
        {
            TurnLeft = TurnRight = false;
        }
        if (MoveForward && MoveBackward)
        {
            MoveForward = MoveBackward = false;
        }

        Fire   = bWantToFire;
        Shield = bWantToShield;

        //Debug.Log(string.Format("MoveLeft: {0} MoveRight: {1} MoveUp: {2} MoveDown: {3}", MoveLeft, MoveRight, MoveUp, MoveDown));
    }
 public override DecisionTreeNode MakeDecision()
 {
     return(root.MakeDecision());
 }