diff options
Diffstat (limited to 'src/entities/antifaShip.c')
-rw-r--r-- | src/entities/antifaShip.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c index 54f5aa9..f2e885b 100644 --- a/src/entities/antifaShip.c +++ b/src/entities/antifaShip.c @@ -33,19 +33,6 @@ void initAntifaShip(Entity * entity, Game * game) { data->timeSinceLastBullet = GetTime(); data->doAutoTarget = false; data->targetedEntityId = ENTITY_NONE; - - // Targeting PID indeed (: - PIDConfig targetingPIDConfig = (PIDConfig){ - .kP = 1000.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! @@ -89,11 +76,10 @@ EntityId getClosestShipToAntifaShip(Game * game, Entity * entity) { return closestId; } -bool isAntifaShipGunInRange(Entity * ship, Entity * targetEntity) { +float getAntifaShipAimDistance(Entity * ship, Entity * targetEntity) { Vector3 directionAiming = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, ship->rotation); Vector3 directionToTarget = Vector3Normalize(Vector3Subtract(targetEntity->position, ship->position)); - - return Vector3Distance(directionAiming, directionToTarget) <= ANTIFA_START_AUTO_TARGET_MAX; + return Vector3Distance(directionAiming, directionToTarget); } void updateAntifaShipTarget(Game * game, Entity * entity) { @@ -110,18 +96,22 @@ void updateAntifaShipTarget(Game * game, Entity * entity) { } else if (targetEntity->fingerprint != data->targetedEntityFingerprint) { data->doAutoTarget = false; return; - } else if (!isAntifaShipGunInRange(entity, targetEntity)) { + } + + // If to far from target. + float aimDistance = getAntifaShipAimDistance(entity, targetEntity); + + if (aimDistance > ANTIFA_START_AUTO_TARGET_MAX) { data->doAutoTarget = false; return; } Vector3 directionToTarget = Vector3Normalize(Vector3Subtract(targetEntity->position, entity->position)); - // Run targeting PID and update target. - float speed = runPID(Vector3Distance(data->gunTarget, directionToTarget), 0.0, &data->targetingPID); + // Update target. + float speed = powf(ANTIFA_TARGETING_SPEED / aimDistance, 2.0); data->gunTarget = Vector3Lerp(data->gunTarget, directionToTarget, speed * t); } else { - resetPID(&data->targetingPID); data->gunTarget = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, entity->rotation); } } @@ -146,7 +136,7 @@ void toggleAntifaShipAutoTarget(Game * game, Entity * entity) { data->targetedEntityFingerprint = closestEntity->fingerprint; // Lock on target if can. - if (isAntifaShipGunInRange(entity, closestEntity)) + if (getAntifaShipAimDistance(entity, closestEntity) <= ANTIFA_START_AUTO_TARGET_MAX) data->doAutoTarget = true; } |