using UnityEngine;
namespace TwoBitMachines.FlareEngine.AI// Include this namespace
{
public class Move : Action // Specify the type of node - Action/Conditional/Composite/Decorator
{
[SerializeField] public Vector2 velocity;
// Use this method to implement the behavior
public override NodeState RunNodeLogic (Root root)
{
if (nodeSetup == NodeSetup.NeedToInitialize)
{
// Any member fields that need to be reset/initialized go here.
}
root.velocity += velocity;// Root is basically the AI
return NodeState.Running; // Return Running
// If the behavior completes, return Success or Failure.
}
// Use this to reset important variables
public override void OnReset ( )
{
}
// Root contains a few variables to be aware of
// root.velocity -- the velocity of the AI, read and write to it
// root.direction -- the direction of the AI on the x-axis, read and write to it
// root.position -- the position of the AI in the game world, read only
// root.hasJumped -- set true if you have added a jumping force to the AI's root.velocity.y
// root.onSurface -- set true if you are creating a hard surface for the AI to stand on
// root.signals.Set ("relevantSignalName") -- set an animation signal if necessary
// root.world -- reference to WorldCollision, read settings like onGround, onMovingPlatform, etc.
// root.gravity -- reference to Gravity, if jumping use root.gravity.SetJump (velocity.y);
// see the Jump node for more information
// root.movingPlatform -- reference to MovingPlatform if the AI is of this type, use it to read
// hasPassengers or passengerCount
}
}
using UnityEngine;
namespace TwoBitMachines.FlareEngine.AI
{
// This is a Conditional node. This will simply check if the AI is on the ground.
// This class doesn't actually exist, but it can be created using this code
// to get this functionality.
public class AIOnGround : Conditional
{
public override NodeState RunNodeLogic (Root root)
{
return root.world.onGround ? NodeState.Success : NodeState.Failure;
}
}
}
using UnityEngine;
namespace TwoBitMachines.FlareEngine.AI
{
// This is a Decorator, and it will run its child node until it fails.
public class UntilFail : Decorator
{
public override NodeState RunNodeLogic (Root root)
{
NodeState nodeState = children[0].RunChild (root);
return nodeState == NodeState.Failure ? NodeState.Success : NodeState.Running;
}
}
}