feat: People go walkies

This commit is contained in:
2025-10-05 16:49:18 +01:00
parent 394366480b
commit 222575b318
7 changed files with 58 additions and 23 deletions

View File

@@ -13,7 +13,7 @@ void updateNPC(F32 delta, NPC *npc, World *world) {
npc->mode = NPC_ACTION_WALKING;
// TODO change targets to poi's rather than just random nodes
npc->targetNavNode = Random_U32(&world->random, 0, world->navMesh->nodeCount);
printf("Starting to nav path\n");
printf("Starting to nav path from %d to %d\n", npc->currentNavNode, npc->targetNavNode);
npc->path = Nav_Path(world->navMesh, npc->currentNavNode, npc->targetNavNode);
printf("done\n");
npc->walkTimer = 0;
@@ -29,14 +29,15 @@ void updateNPC(F32 delta, NPC *npc, World *world) {
npc->mode = NPC_ACTION_WAITING;
npc->maxWaitTime = Random_F32(&world->random, 10, 40);
npc->waitTime = 0;
npc->currentNavNode = npc->targetNavNode;
npc->pathIndex = 0;
return;
}
npc->pathIndex+=1;
npc->currentNavNode = npc->path.indexes[npc->pathIndex];
npc->pathIndex+=1;
}
NavNode cNav = world->navMesh->nodes[npc->currentNavNode];
NavNode tNav = world->navMesh->nodes[npc->pathIndex];
NavNode tNav = world->navMesh->nodes[npc->path.indexes[npc->pathIndex]];
npc->collision.pos.x = cNav.pos.x * (1 - npc->walkTimer/NPC_SPEED) + tNav.pos.x * npc->walkTimer/NPC_SPEED;
npc->collision.pos.y = cNav.pos.y * (1 - npc->walkTimer/NPC_SPEED) + tNav.pos.y * npc->walkTimer/NPC_SPEED;
break;