Unity Advanced: behavior tree to build 02 Capture the Flag battle scenes, AI script, pick up the flag

Copyright notice:

  • This article Original starting in the following website:
  1. Blog Park "excellent dream maker culture" in space: https: //www.cnblogs.com/raymondking123
  2. Excellent dream maker culture official blog: https: //91make.top
  3. Excellent game dream maker culture lecture: https: //91make.ke.qq.com
  4. "Excellent dream maker culture" of micro-channel public number: umaketop
  • You are free to reprint, but must include the full copyright notice

Scene set up renderings

Figure showing GIF (Capture the Flag, Capture the Flag to the end)


Decorators: single task operating
Composites: Composite Task
Conditionals: making a judgment
Actions: do Behavior

1 find banner behavior tree

Flee away from the target
Inverter: negated
create global variables: OffenseSpeed, AngularSpeed.
Principle: Do you see the enemy, did not see the banner go negated, see the enemy far away from the enemy, Sequence interrupt type selected Self

Find banner tree model behavior

Adding behavior tree

add notes

Create a global variable

You can switch the behavior of the tree

Behavior flag to the end to find the tree 2

Get the flag to the end, did not get the flag, banner chase
script to determine whether to get the flag, run success or failure.

public class IsHasFlag :Conditional {
    private Offense offense;
    public override void OnAwake()
    {
        offense = this.GetComponent<Offense>();
    }
    public override TaskStatus OnUpdate()
    {
        if (offense.hasFlag)
        {
            return TaskStatus.Success;
        }
        return TaskStatus.Failure;
    }
}

Add banner above script to determine whether the tag is a collision of players, to collision of a boll value, and let the flag collision coordinate equal players, with a look to make the flag go

   private Offense owner;
    public void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Offense")
        {
            if (owner != null)
            {
                owner.hasFlag = false;
            }
            other.GetComponent<Offense>().hasFlag = true;
            transform.parent = other.transform;
            owner = other.GetComponent<Offense>();

        }
    }
}

Guess you like

Origin www.cnblogs.com/raymondking123/p/11416296.html