Skip to content

Commit

Permalink
fix: guntower ai aiming midpoints, targets, and turning speed
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Sep 21, 2023
1 parent 4c7e428 commit b6df7d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
8 changes: 7 additions & 1 deletion core/src/me/vinceh121/wanderer/character/CharacterW.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public void onJumpEnd(final boolean bigJump) {
.playSource3D()
.setPosition(CharacterW.this.getTransform().getTranslation(new Vector3()));
CharacterW.this.eventDispatcher.dispatchEvent(new Event(CharacterW.EVENT_JUMP_END));
CharacterW.this.justRan = CharacterW.this.justBackedUp = CharacterW.this.justTurnedLeft = CharacterW.this.justTurnedRight = false;
CharacterW.this.justRan = CharacterW.this.justBackedUp =
CharacterW.this.justTurnedLeft = CharacterW.this.justTurnedRight = false;
}

@Override
Expand Down Expand Up @@ -468,6 +469,11 @@ public void dispose() {
super.dispose();
}

@Override
public Vector3 getMidPoint() {
return this.getTranslation().add(0, this.meta.getCapsuleHeight() / 2f, 0);
}

/**
* @return the meta
*/
Expand Down
8 changes: 8 additions & 0 deletions core/src/me/vinceh121/wanderer/entity/AbstractEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ protected void updateTransform() {
}
}

public Vector3 getMidPoint() {
if (this.collideObject != null) {
return this.collideObject.getCenterOfMassPosition();
}

return this.getTranslation();
}

public void addModel(final DisplayModel value) {
this.models.add(value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package me.vinceh121.wanderer.guntower;

import java.util.HashSet;
import java.util.Set;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;

import me.vinceh121.wanderer.Wanderer;
import me.vinceh121.wanderer.ai.AIController;
import me.vinceh121.wanderer.entity.AbstractEntity;
import me.vinceh121.wanderer.entity.ILivingEntity;
import me.vinceh121.wanderer.util.MathUtilsW;

public class GuntowerAiController extends AIController<AbstractGuntower> {
private final Array<String> targets = new Array<>(true, 5);
private float range = 500, turnSpeed = 5;
private final Set<String> targets = new HashSet<>();
private float range = 500, turnSpeed = 3;

public GuntowerAiController(Wanderer game, AbstractGuntower target) {
super(game, target);
Expand All @@ -26,7 +27,7 @@ public void tick(float delta) {
for (final AbstractEntity e : this.game.getEntities()) {
final float dist = this.target.getTranslation().dst(e.getTranslation());

if (dist < minDist && e != this.target && e instanceof ILivingEntity) {
if (dist < minDist && e != this.target && targets.contains(e.getClass().getCanonicalName())) {
closest = e;
minDist = dist;
}
Expand All @@ -36,12 +37,12 @@ public void tick(float delta) {
return;
}

final Vector3 closestDir = closest.getTranslation()
final Vector3 closestDir = closest.getMidPoint()
.cpy()
.sub(this.target.getTranslation().add(0, this.target.getAverageTurretPosition().y, 0))
.nor();

final Vector3 newDir = this.target.getLookDirection().slerp(closestDir, delta);
final Vector3 newDir = this.target.getLookDirection().slerp(closestDir, this.turnSpeed * delta);
// Vector3 newDir = closestDir.cpy();
newDir.rotateRad(Vector3.X, MathUtils.HALF_PI);

Expand Down

0 comments on commit b6df7d1

Please sign in to comment.