Channel Operator Goto
In the first Channel Operator Tutorial, you learned how to use the Channel Operators to let entities gather in the scene. This tutorial will teach you how to use the Channel Operators to follow the target of a Go To Behavior.
An entity going to its Go To target by using Channel Operators
Starting from a simple scene already populated with no behavior, here are the steps that will be covered by this tutorial:
- Basic startup
- Starting to move when the Go To behavior is started
- Getting and using the Go To target to provide the moving direction
Basic startup
The starting point for this tutorial is a populated scene with entity(s), and a Terrain. Check the Quick Start Tutorial if needed.
1. Start by adding a Go To behavior with a target across the environment.
The added Locomotion behavior, configured in Direct Mode controlled by animation
If you run the simulation at this point, the entity should not be moving. There is no navigation behavior to reach the target, and nothing else is driving the locomotion, so the entity should just play the rest motion.
Starting to move when the Go To behavior is started
To start moving when the Go To behavior starts, the idea is to use the Channel Operator behavior to set a desired speed when the entity has a Go To target, and reset it when it's not the case. Here is how to do this:
1. Open the Behavior editor, and add a Channel Operator Behavior on the entity type
2. Select the Channel Operator Behavior and Add a New Output Channel
Next steps will explains how to build the following graph of channel operators:
Graph of channel operators that select a speed depending on the hasAGoToTarget property of the entity
3. Select the newly created output channel and configure the Output Channel to output the to Entity Desired Speed, and rename it "outputDesiredSpeed"
4. Select the "outputDesiredSpeed" node, and add a previous ChOpMultiplexer
This stage will select the desired speed when the entity has a goto target, or a zero speed when it has no target.
Configure the Multiplexer Mode to Select Maximum and rename it "speedSelection"
5. When the "speedSelection" node was created, it should have create a ChOpInput connected to the first PreviousChOps plug (if not, then create one)
This input node will be the zero speed. Configure the Expression to "0" and rename it "nullSpeed".
4. Select the "speedSelection" node again, and add a previous ChOpInput
This input node will be the default navigation speed. Configure the Expression to "1.1" (or any other value depending on the scale of your entities) and rename it "defaultSpeed".
4. Select the "speedSelection" node again, and add a previous ChOpInput
This input node will be the weight that will be used to choose the default speed. We need the default speed to be selected whenever the entity has a local target, so configure the Expression to "this.hasAGoToTarget" and rename it "hasAGoToTarget" (check out the Channel documentation for all available input channels).
The entities should now starts walking only when the goto behavior is started. Configure its start trigger to any kind of trigger you need.
Getting and using the Go To target to provide the moving direction
Up to this point, the entity should walk straightforward, and nothing allows it to follow the goto target. The position of the current local goto target (the local goto target is the current point on the path to the final target that is visible to the entity) can be get trough a Channel. Everything else is just a matter of converting this position into a direction to follow. It should look like that:
Complete graph of channel operator to follow a goto behavior
1. Select the Channel Operator Behavior and Add a New Output Channel
2. Select the newly created output channel and configure the Output Channel to output the to Entity Desired Move Orientation, and rename it "moveOrientationOutput"
3. Select the "moveOrientationOutput" node, and add a previous ChOpConverter
This stage will convert a desired moving direction (a vector3) into a moving orientation angle.
Configure the Converter Mode to "World Direction To World Angle" and rename it "worldAngleTowardsLocalTarget"
4. Select the "worldAngleTowardsLocalTarget" node, and add a previous ChOpOperation
This will substract the local goto target with the current entity position to get a vector pointing toward the target.
Configure the Operator to "-" and rename it "vectorToLocalTargetShape".
5. Select the "vectorToLocalTargetShape" node, and add a previous ChOpInput
This input node will be the goto local target position.
Configure the Expression to "this.localGoToTargetPosition" and rename it "gotoLocalTargetInputShape".
5. Select the "vectorToLocalTargetShape" node again, and add a previous ChOpInput
This input node will be the entity current position.
Configure the Expression to "this.position" and rename it "entityPositionShape".
The simulated entity should now be following the path to its target whenever the goto behavior is started.
An entity going to its Go To target by using Channel Operators