diff --git a/assets/behaviors/common/doRandomMove.behavior b/assets/behaviors/common/doRandomMove.behavior index d411b4cf..b674529a 100644 --- a/assets/behaviors/common/doRandomMove.behavior +++ b/assets/behaviors/common/doRandomMove.behavior @@ -1,6 +1,8 @@ { sequence : [ - set_target_nearby_block, + { + set_target_nearby_block : { moveProbability: 65 } + }, move_to ] } diff --git a/src/main/java/org/terasology/minion/move/MoveToAction.java b/src/main/java/org/terasology/minion/move/MoveToAction.java index b9ef0426..b932c8fa 100644 --- a/src/main/java/org/terasology/minion/move/MoveToAction.java +++ b/src/main/java/org/terasology/minion/move/MoveToAction.java @@ -80,17 +80,18 @@ private boolean processDirect(Actor actor, MinionMoveComponent moveComponent) { targetDirection.sub(moveComponent.target, worldPos); Vector3f drive = new Vector3f(); - // TODO review - is the yaw here being calculated properly? float yaw = (float) Math.atan2(targetDirection.x, targetDirection.z); + float requestedYaw = 180f + yaw * TeraMath.RAD_TO_DEG; + - if (targetDirection.x * targetDirection.x + targetDirection.z * targetDirection.z <= distance * distance) { + if((targetDirection.x < distance) && (targetDirection.y < distance) && (targetDirection.z < distance)) { drive.set(0, 0, 0); reachedTarget = true; + requestedYaw = 0f; } else { targetDirection.normalize(); drive.set(targetDirection); } - float requestedYaw = 180f + yaw * TeraMath.RAD_TO_DEG; CharacterMoveInputEvent wantedInput = new CharacterMoveInputEvent(0, 0, requestedYaw, drive, false, false, moveComponent.jumpMode, (long) (actor.getDelta() * 1000)); actor.getEntity().send(wantedInput); diff --git a/src/main/java/org/terasology/minion/move/SetTargetToNearbyBlockNode.java b/src/main/java/org/terasology/minion/move/SetTargetToNearbyBlockNode.java index 4ccfa44e..bbe59f1f 100644 --- a/src/main/java/org/terasology/minion/move/SetTargetToNearbyBlockNode.java +++ b/src/main/java/org/terasology/minion/move/SetTargetToNearbyBlockNode.java @@ -32,29 +32,31 @@ @BehaviorAction(name = "set_target_nearby_block") public class SetTargetToNearbyBlockNode extends BaseAction { - private static final int RANDOM_BLOCK_ITERATIONS = 10; private static final Logger logger = LoggerFactory.getLogger(SetTargetToNearbyBlockNode.class); private transient Random random = new Random(); @In private PathfinderSystem pathfinderSystem; + private int moveProbability = 100; @Override public BehaviorState modify(Actor actor, BehaviorState result) { - MinionMoveComponent moveComponent = actor.getComponent(MinionMoveComponent.class); - if (moveComponent.currentBlock != null) { - WalkableBlock target = findRandomNearbyBlock(moveComponent.currentBlock); - moveComponent.target = target.getBlockPosition().toVector3f(); - actor.save(moveComponent); - } else { - return BehaviorState.FAILURE; + if (random.nextInt(100) > (99 - moveProbability)) { + MinionMoveComponent moveComponent = actor.getComponent(MinionMoveComponent.class); + if (moveComponent.currentBlock != null) { + WalkableBlock target = findRandomNearbyBlock(moveComponent.currentBlock); + moveComponent.target = target.getBlockPosition().toVector3f(); + actor.save(moveComponent); + } else { + return BehaviorState.FAILURE; + } } return BehaviorState.SUCCESS; } private WalkableBlock findRandomNearbyBlock(WalkableBlock startBlock) { WalkableBlock currentBlock = startBlock; - for (int i = 0; i < RANDOM_BLOCK_ITERATIONS; i++) { + for (int i = 0; i < random.nextInt(10) + 1; i++) { WalkableBlock[] neighbors = currentBlock.neighbors; List existingNeighbors = Lists.newArrayList(); for (WalkableBlock neighbor : neighbors) { @@ -66,7 +68,6 @@ private WalkableBlock findRandomNearbyBlock(WalkableBlock startBlock) { currentBlock = existingNeighbors.get(random.nextInt(existingNeighbors.size())); } } - logger.debug(String.format("Looking for a block: my block is %s, found destination %s", startBlock.getBlockPosition(), currentBlock.getBlockPosition())); return currentBlock; }