From 77a06748f9f394486cad833e2ca351e8dbcc7361 Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Sun, 16 Jul 2023 21:55:38 -0600 Subject: More following shit --- src/entities/soldato.c | 53 +++++++++++++++++++++++++++++++++++++------------- src/entities/soldato.h | 5 +++++ 2 files changed, 44 insertions(+), 14 deletions(-) (limited to 'src/entities') 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); -- cgit v1.2.3