aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-10-28 15:54:52 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-10-28 15:54:52 -0600
commit60fce38926856e1842aab7c14be99336f34b733f (patch)
tree572eb55b0966c9e6f360417cb3b1ab689a64183f
parentfa14227560c9be143b7c26ada4e41c6636966896 (diff)
Using distance from target for targeting speed now
-rw-r--r--src/entities/antifaShip.c32
-rw-r--r--src/entities/antifaShip.h3
2 files changed, 12 insertions, 23 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;
}
diff --git a/src/entities/antifaShip.h b/src/entities/antifaShip.h
index 7474b00..ce5c71f 100644
--- a/src/entities/antifaShip.h
+++ b/src/entities/antifaShip.h
@@ -1,7 +1,6 @@
#include "gameCommon.h"
#include "entity.h"
#include "bullets.h"
-#include "PID.h"
#ifndef ANTIFA_SHIP_H
#define ANTIFA_SHIP_H
@@ -12,6 +11,7 @@
// Auto target shit.
#define ANTIFA_START_AUTO_TARGET_MAX 0.5 // How far off auto target can be entail it drops.
+#define ANTIFA_TARGETING_SPEED 0.5
typedef struct AntifaShip {
Vector2 lastMouse;
@@ -23,7 +23,6 @@ typedef struct AntifaShip {
Vector3 gunTarget;
bool doAutoTarget;
- PID targetingPID;
EntityId targetedEntityId;
EntityFingerprint targetedEntityFingerprint;
} AntifaShip;