MoveToAction Node - Terasology/TutorialPathfinding GitHub Wiki
MoveToAction
This section will introduce you to the most fundamental movement node in Terasology which is used by more complex behaviors. Check out Walking Along a Path to get a basic idea if you'd like to.
When you spawn, you have 2 blocks with you. A spawner block (which is a birch cube), and a target block (which is a birch flower type thing). Place the spawner block and target block and activate item 1. You should see a white floating cube on top of the spawner block. Notice how it doesn't do anything? That's because we haven't added any behaviors to it. Open up baseGooey.prefab located in assets/prefabs of TutorialPathfinding.
{
"alwaysRelevant": true,
"persisted" : true,
"BoxShape" : {
"extents" : [1, 1, 1]
},
"RigidBody" : {
},
"skeletalmesh" : {
"mesh" : "engine:floatingCube",
"heightOffset" : 0,
"material" : "engine:floatingCubeSkin",
"animationPool": [
"engine:floatingCubeIdle"
],
"loop" : true,
"scale" : [1, 1, 1]
},
"Location": {},
"Character": {},
"AliveCharacter": {},
"CharacterMovement" : {
"groundFriction": 16,
"speedMultiplier": 0.3,
"distanceBetweenFootsteps": 0.2,
"distanceBetweenSwimStrokes": 2.5,
"height": 1.0,
"radius": 0.5,
"jumpSpeed": 12
}
}
Let us add a MinionMoveComponent since a lot of the behavior nodes depend on the values stored inside this component.
"MinionMove": {}
Next let's add some behavior. Define a behavior file, basicMoveTo.behavior. Add these lines of code.
{
sequence: [
{
set_speed : {
speedMultiplier: 2
}
},
{
loop: {
child: {
sequence: [
{
move_to: {}
}
]
}
}
}
]
}
The set_speed node sets the speed of the entity. The loop control node keeps repeating the sequence a number of times and the move_to behavior is the node that actually does the moving. It makes the Actor move in a straight line to whatever it's MinionMoveComponent's target points to. To link the behavior and the entity, add this to the prefab.
"Behavior": {
"tree": "TutorialPathfinding:basicPathfinding"
}
One final thing to do. We need to actually set the MinionMoveComponent's target to the position of the target block. Open SpawnSystem in org.terasology.tutorialpathfinding.systems
Add this line of code.
MinionMoveComponent minionMoveComponent = builder.getComponent(MinionMoveComponent.class);
minionMoveComponent.target = JomlUtil.from(targetPostion);
The entity should now move to the target block once spawned!