From f27718cdbf718deb156a3feaac63e4bfa689c086 Mon Sep 17 00:00:00 2001 From: Klemen Plestenjak Date: Thu, 7 Dec 2023 18:45:31 +0100 Subject: [PATCH] Fix bug in path following system --- game/systems_entity.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/game/systems_entity.c b/game/systems_entity.c index 994f947..69acafb 100644 --- a/game/systems_entity.c +++ b/game/systems_entity.c @@ -149,10 +149,7 @@ void entityFollowPath(ecs_iter_t *it) { Path *path = ecs_field(it, Path, 1); for (i32 i = 0; i < it->count; i++) { - ecs_entity_t entity = it->entities[i]; - - Path *entityPath = &path[i]; - TargetPosition target = entityPath->paths->waypoints[entityPath->curWaypoint]; + const ecs_entity_t entity = it->entities[i]; if (!ecs_has(ECS, entity, TargetPosition)) { if (path[i].curWaypoint >= path[i].paths->numWaypoints) { @@ -162,8 +159,12 @@ void entityFollowPath(ecs_iter_t *it) { path[i].paths = path[i].paths->next; if (!path[i].paths) ecs_remove(ECS, it->entities[i], Path); } - ecs_set_ptr(ECS, entity, TargetPosition, &target); - path[i].curWaypoint++; + if (path[i].paths) { + TargetPosition target = path[i].paths->waypoints[path[i].curWaypoint]; + path[i].curWaypoint++; + ecs_set_ptr(ECS, entity, TargetPosition, &target); + } + } } }