HOWTO: Create a custom Move To node
Below is an example of a custom Move To
node that runs gameplay-related code to provide movement action for gameplay objects. Default node logic calls virtual AddMovement()
method on a target actor.
Warning
If you want to store additional per-instance data for a custom movement node then use C++ script and make your state structure to inherit from BehaviorTreeMoveToNode::State
. Otherwise, implement a custom movement node.
using FlaxEngine;
/// <summary>
/// Custom move node.
/// </summary>
public class MyMoveToNode : BehaviorTreeMoveToNode
{
/// <inheritdoc />
public override void GetAgentSize(Actor agent, out float outRadius, out float outHeight)
{
// Here you can provide custom size of the agent (radius and height) or use default values queried from actor type
base.GetAgentSize(agent, out outRadius, out outHeight);
}
/// <inheritdoc />
public override NavMeshRuntime GetNavMesh(Actor agent)
{
// Here you can override navmesh to be used for the given agent
return base.GetNavMesh(agent);
}
/// <inheritdoc />
public override bool Move(Actor agent, Vector3 move)
{
// Here you can perform custom movement logic (eg. via entity interface or similar)
// It's always called on a main-thread during game Update so here you safely can modify state of the game
// Return true if cannot apply move (node will fail)
return base.Move(agent, move);
}
}