diff options
author | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-07-16 21:55:38 -0600 |
---|---|---|
committer | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-07-16 21:55:38 -0600 |
commit | 77a06748f9f394486cad833e2ca351e8dbcc7361 (patch) | |
tree | c325ae88a7fa566217fef9ad5e7851fa600516b1 /src/entities | |
parent | ed1704f9a110c9fa909dccb3169bf388f48279e4 (diff) |
More following shit
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/soldato.c | 53 | ||||
-rw-r--r-- | src/entities/soldato.h | 5 |
2 files changed, 44 insertions, 14 deletions
diff --git a/src/entities/soldato.c b/src/entities/soldato.c index f19faa7..30dfa6b 100644 --- a/src/entities/soldato.c +++ b/src/entities/soldato.c @@ -3,27 +3,52 @@ void initSoldato(Entity * entity, Game * game) { entity->model = &game->assets.models[SOLDATO_ASSET]; + + // Acceleration. + entity->useAcceleration = true; + entity->acceleration = (EntityAcceleration){ + .speedUp = 5.0, + .speedDown = 0.00001 + }; + + // PID configs. + PIDConfig speedPIDConfig = { + .kP = -0.5, + .kI = 0.0, + .kD = 0.0, + .angleMode = false, + .doClamp = true, + .min = 0.0, + .max = 30.0 + }; + + // Allocate data. + entity->data = KF_MALLOC(sizeof(Soldato)); + + if (entity->data == NULL) { + ALLOCATION_ERROR; + return; + } + + Soldato * data = (Soldato*)entity->data; + data->speedPID = createPID(speedPIDConfig); } void closeSoldato(Entity * entity) { + if (entity->data != NULL) + KF_FREE(entity->data); } void updateSoldato(Game * game, Entity * entity) { Entity * player = getEntityFromWorld(game->world, 0); - - // Get direction. - Vector3 direction = Vector3Subtract(entity->position, player->position); - direction = Vector3Normalize(direction); - - // Get look at and rotation. - Matrix matrix = MatrixLookAt(Vector3Zero(), direction, (Vector3){0, 1, 0}); - Quaternion rotation = QuaternionFromMatrix(matrix); - rotation = QuaternionInvert(rotation); - - entity->rotation = rotation; - - entity->velocity.velocity = Vector3Scale(direction, -10.0); - entityUpdatePosition(entity); + Soldato * data = (Soldato*)entity->data; + + entityFlightToPoint( + entity, + player->position, + &data->speedPID, + 5.0 + ); } void drawSoldato(Game * game, Entity * entity) { diff --git a/src/entities/soldato.h b/src/entities/soldato.h index 6992e00..5123aee 100644 --- a/src/entities/soldato.h +++ b/src/entities/soldato.h @@ -1,9 +1,14 @@ #include "gameCommon.h" #include "entity.h" +#include "PID.h" #ifndef SOLDATO_H #define SOLDATO_H +typedef struct Soldato { + PID speedPID; +} Soldato; + void initSoldato(Entity * entity, Game * game); void closeSoldato(Entity * entity); void updateSoldato(Game * game, Entity * entity); |