aboutsummaryrefslogtreecommitdiff
path: root/src/entities/soldato.c
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-07-16 18:57:08 -0600
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-07-16 18:57:08 -0600
commited1704f9a110c9fa909dccb3169bf388f48279e4 (patch)
treeb153bddd10a82dbcb7c5c3253e3466b61d5326ba /src/entities/soldato.c
parent9eeb5293fc0d022298fb772338241aa7e8672dac (diff)
Chatgpt saved my ass again
Diffstat (limited to 'src/entities/soldato.c')
-rw-r--r--src/entities/soldato.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/entities/soldato.c b/src/entities/soldato.c
index da8df84..f19faa7 100644
--- a/src/entities/soldato.c
+++ b/src/entities/soldato.c
@@ -3,14 +3,27 @@
void initSoldato(Entity * entity, Game * game) {
entity->model = &game->assets.models[SOLDATO_ASSET];
- entity->velocity.angularVelocity = (AxisAngle){(Vector3){1.0, 1.0, 1.0}, 1.0};
}
void closeSoldato(Entity * entity) {
}
void updateSoldato(Game * game, Entity * entity) {
- entityUpdateRotation(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);
}
void drawSoldato(Game * game, Entity * entity) {