aboutsummaryrefslogtreecommitdiff
path: root/src/entities/antifaShip.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/antifaShip.c')
-rw-r--r--src/entities/antifaShip.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index c89c820..fbcb138 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -33,8 +33,23 @@ void initAntifaShip(Entity * entity, Game * game) {
data->timeSinceLastBullet = GetTime();
data->doAutoTarget = false;
data->targetedEntityId = ENTITY_NONE;
+
+ // Targeting PID indeed (:
+ PIDConfig targetingPIDConfig = (PIDConfig){
+ .kP = 500.0,
+ .kI = 0.1,
+ .kD = 0.0,
+ .angleMode = false,
+ .doClamp = false,
+ .min = 0.0,
+ .max = 0.0
+ };
+
+ data->targetingPID = createPID(targetingPIDConfig);
}
+// Go back to burger king you elon musking loving mother fucker!
+
void closeAntifaShip(Entity * entity) {
if (entity->data != NULL)
KF_FREE(entity->data);
@@ -101,9 +116,12 @@ void updateAntifaShipTarget(Game * game, Entity * entity) {
}
Vector3 directionToTarget = Vector3Normalize(Vector3Subtract(targetEntity->position, entity->position));
- data->gunTarget = Vector3Lerp(data->gunTarget, directionToTarget, ANTIFA_AUTO_TARGET_SPEED * t);
- printf("%d %d\n", isAntifaShipGunInRange(entity, targetEntity), data->targetedEntityId);
+
+ // Run targeting PID and update target.
+ float speed = runPID(Vector3Distance(data->gunTarget, directionToTarget), 0.0, &data->targetingPID);
+ data->gunTarget = Vector3Lerp(data->gunTarget, directionToTarget, speed * t);
} else {
+ resetPID(&data->targetingPID);
data->gunTarget = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, entity->rotation);
}
}