Fix bug in path following system

This commit is contained in:
2023-12-07 18:45:31 +01:00
parent eac2d676d6
commit f27718cdbf

View File

@@ -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);
}
}
}
}