Skip to content

Commit

Permalink
feat: stop moving at target
Browse files Browse the repository at this point in the history
  • Loading branch information
HamaIndustries committed Nov 3, 2024
1 parent 3909b6b commit 598b161
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/main/java/symbolics/division/armistice/mecha/ChassisPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ChassisPart extends AbstractMechaPart {
protected boolean legsReady = false;
protected Vec3 prevPos = Vec3.ZERO;
private boolean firstTick = true;
private boolean atRest = true;

// todo notes: chassis schematic/skeleton needs to tell us
// - number of legs
Expand Down Expand Up @@ -142,6 +143,7 @@ public void serverTick() {

// update desired movement
if (pathingTarget != null && !pathingTarget.closerThan(new Vec3(absPos()).with(Direction.Axis.Y, pathingTarget.y), followTolerance)) {
atRest = false;
// if we're not facing the target, try to rotate towards it.
Vec3 targetHorizontalDir = pathingTarget.subtract(core.position()).with(Direction.Axis.Y, 0).normalize();
if (direction().dot(targetHorizontalDir) < 0.95) {
Expand All @@ -156,6 +158,7 @@ public void serverTick() {
legMap.setMapRotation(0);
}
} else {// don't need to go anywhere, give our legs a rest
atRest = true;
legMap.setMapOffset(Vec3.ZERO);
legMap.setMapRotation(0);
}
Expand Down Expand Up @@ -186,7 +189,7 @@ public void serverTick() {
// move to centroid
if (prevPos == Vec3.ZERO) prevPos = core.position();
var curPos = IKUtil.f2m(skeleton.getChain(0).getBone(0).getEndLocation());
float ticksPerBlock = 2;
float ticksPerBlock = 4;
var delta = desiredPos.subtract(curPos);
Vec3f tgt = IKUtil.m2f(curPos.add(delta.normalize().scale(1 / ticksPerBlock)));

Expand All @@ -212,7 +215,9 @@ public void serverTick() {
}

if (ArmisticeDebugValues.ikSolving) {
skeleton.solveForTarget(tgt);
if (!atRest) {
skeleton.solveForTarget(tgt);
}
legsReady = true;
}
core.entity().setPos(IKUtil.f2m(skeleton.getChain(0).getBone(0).getEndLocation()));
Expand All @@ -237,6 +242,10 @@ public void serverTick() {
new Vec3(movement.x, 0, movement.z);
}

public boolean atRest() {
return atRest;
}

@Override
public void clientTick(float tickDelta) {
super.clientTick(tickDelta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ public void tick() {
Vec3 mapTarget = chassis.legMap().legTarget(legIndex);
Vec3 tip = tipPos();
float mapDelta = (float) mapTarget.distanceTo(tip);
boolean inRange = mapDelta <= chassis.legMap().stepTolerance();
double horzMapDelta = mapTarget.multiply(1, 0, 1).distanceTo(tip.multiply(1, 0, 1));
boolean inRange = horzMapDelta <= chassis.legMap().stepTolerance();


// check if we need to do a new step
if (!stepping() && !inRange && !chassis.neighborsStepping(legIndex)) {
if (!chassis.atRest() && !stepping() && !inRange && !chassis.neighborsStepping(legIndex)) {
if (prevStepTarget != finalStepTarget) {
prevStepTarget = tip;
}
Expand Down Expand Up @@ -212,7 +213,7 @@ protected Vec3 nearestValidStepPosition(Vec3 ideal) {
int checkHeight = 10;
var step = level.findSupportingBlock(entity,
new AABB(
ideal.add(1, checkHeight, 1), ideal.subtract(-1, checkHeight, -1)
ideal.add(1, checkHeight * 2, 1), ideal.subtract(-1, checkHeight * 3, -1)
)
);
return step.map(BlockPos::getCenter).orElse(ideal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LegMap {
protected final Vec3 centroidOffset;
protected Vec3 mapOffset = Vec3.ZERO;
protected float mapYaw = 0;
protected double stepTolerance = 3;
protected double stepTolerance = 5;
protected double[] directionWeights;

public LegMap(MechaModelData data, ChassisPart chassis) {
Expand Down

0 comments on commit 598b161

Please sign in to comment.