-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
216 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
assets/behaviors/pathfinding/dynamicPathfindingFollow.behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
sequence: [ | ||
{ | ||
animation : { | ||
play: "engine:Walk.animationPool", | ||
loop: "engine:Walk.animationPool" | ||
} | ||
}, | ||
{ | ||
set_speed : { | ||
speedMultiplier: 0.4 | ||
} | ||
}, | ||
{ | ||
loop: { | ||
child: { | ||
sequence: [ | ||
set_target_to_followed_entity, | ||
find_path, | ||
setup_continuous_pathfinding, | ||
{ | ||
timeout: { | ||
time: 3, | ||
child: { | ||
move_along_path_continuous: { | ||
child: { | ||
move_to: {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
31 changes: 31 additions & 0 deletions
31
assets/behaviors/pathfinding/pointPathfindingFollow.behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
sequence: [ | ||
{ | ||
animation : { | ||
play: "engine:Walk.animationPool", | ||
loop: "engine:Walk.animationPool" | ||
} | ||
}, | ||
{ | ||
set_speed : { | ||
speedMultiplier: 0.4 | ||
} | ||
}, | ||
{ | ||
loop: { | ||
child: { | ||
sequence: [ | ||
find_path, | ||
{ | ||
move_along_path: { | ||
child: { | ||
move_to: {} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
32 changes: 32 additions & 0 deletions
32
assets/behaviors/pathfinding/staticPathfindingFollow.behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
sequence: [ | ||
{ | ||
animation : { | ||
play: "engine:Walk.animationPool", | ||
loop: "engine:Walk.animationPool" | ||
} | ||
}, | ||
{ | ||
set_speed : { | ||
speedMultiplier: 0.4 | ||
} | ||
}, | ||
{ | ||
loop: { | ||
child: { | ||
sequence: [ | ||
set_target_to_followed_entity, | ||
find_path, | ||
{ | ||
move_along_path: { | ||
child: { | ||
move_to: {} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/org/terasology/minion/move/ContinuousMoveAlongPathNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2018 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terasology.minion.move; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.terasology.logic.behavior.BehaviorAction; | ||
import org.terasology.logic.behavior.core.Actor; | ||
import org.terasology.logic.behavior.core.BaseAction; | ||
import org.terasology.logic.behavior.core.BehaviorState; | ||
import org.terasology.logic.location.LocationComponent; | ||
import org.terasology.math.geom.Vector3f; | ||
import org.terasology.navgraph.WalkableBlock; | ||
import org.terasology.pathfinding.componentSystem.PathRenderSystem; | ||
import org.terasology.pathfinding.model.Path; | ||
import org.terasology.registry.CoreRegistry; | ||
|
||
/** | ||
* Call child node, as long as the actor has not reached the end of the path. Sets <b>MinionMoveComponent.target</b> to | ||
* next step in path.<br/> Old construct() from original {@link MoveAlongPathNode} moved to | ||
* {@link SetupContinuousMoveNode} to allow for path travelling to be interrupted. This enables a character to follow | ||
* a moving target. | ||
* <br/> | ||
* <b>SUCCESS</b>: when actor has reached end of path.<br/> | ||
* <b>FAILURE</b>: if no path was found previously.<br/> | ||
* <br/> | ||
*/ | ||
@BehaviorAction(name = "move_along_path_continuous", isDecorator = true) | ||
public class ContinuousMoveAlongPathNode extends BaseAction { | ||
|
||
@Override | ||
public BehaviorState modify(Actor actor, BehaviorState result) { | ||
MinionMoveComponent moveComponent = actor.getComponent(MinionMoveComponent.class); | ||
if (result != BehaviorState.SUCCESS) { | ||
return result; | ||
} | ||
moveComponent.currentIndex++; | ||
if (moveComponent.currentIndex < moveComponent.path.size()) { | ||
WalkableBlock block = moveComponent.path.get(moveComponent.currentIndex); | ||
Vector3f pos = block.getBlockPosition().toVector3f(); | ||
pos.add(new Vector3f(0, 1, 0)); | ||
moveComponent.target = pos; | ||
actor.save(moveComponent); | ||
return BehaviorState.RUNNING; | ||
} else { | ||
moveComponent.path = null; | ||
actor.save(moveComponent); | ||
return BehaviorState.SUCCESS; | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/org/terasology/minion/move/SetupContinuousMoveNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2018 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.terasology.minion.move; | ||
|
||
import org.terasology.logic.behavior.BehaviorAction; | ||
import org.terasology.logic.behavior.core.Actor; | ||
import org.terasology.logic.behavior.core.BaseAction; | ||
import org.terasology.logic.behavior.core.BehaviorState; | ||
import org.terasology.navgraph.WalkableBlock; | ||
import org.terasology.pathfinding.model.Path; | ||
|
||
/** | ||
* Essential setup for a character to travel along a determined path. This is exported from | ||
* {@link MoveAlongPathNode#construct(Actor)}, which allows for characters to interrupt travelling along a path. | ||
* This is essential for characters following a moving object. | ||
*/ | ||
@BehaviorAction(name = "setup_continuous_pathfinding") | ||
public class SetupContinuousMoveNode extends BaseAction { | ||
|
||
@Override | ||
public BehaviorState modify(Actor actor, BehaviorState result) { | ||
|
||
MinionMoveComponent moveComponent = actor.getComponent(MinionMoveComponent.class); | ||
if (moveComponent != null && moveComponent.path != null && moveComponent.path != Path.INVALID) { | ||
moveComponent.currentIndex = 0; | ||
WalkableBlock block = moveComponent.path.get(moveComponent.currentIndex); | ||
moveComponent.target = block.getBlockPosition().toVector3f(); | ||
actor.save(moveComponent); | ||
|
||
return BehaviorState.SUCCESS; | ||
} | ||
|
||
return BehaviorState.FAILURE; | ||
} | ||
|
||
} |