Use center position for path following, tweak proximity threshold

This commit is contained in:
2024-02-13 13:13:43 +01:00
parent 7d8dec5ef7
commit acebdceb6c
6 changed files with 15 additions and 12 deletions

View File

@@ -383,7 +383,7 @@ void loadMap(Game *game, const char *path, bool mainMenu) {
.harvestTarget = nearest.entity,
.harvestPos = nearest.pos
},
.proximity = 3.0f,
.proximity = 8.0f,
});
Worker *worker = ecs_get_mut(ECS, workers[i].entity, Worker);
worker->carryRes = resType;

View File

@@ -41,8 +41,8 @@ void setAIBehaviour(ecs_entity_t entity, const BzBTNode *root,
if (blackboard) {
AIBlackboard *b = ecs_get_mut(ECS, entity, AIBlackboard);
*b = *blackboard;
if (b->proximity < 2.0f)
b->proximity = 2.0f;
if (b->proximity < 4.0f)
b->proximity = 4.0f;
}
BzBTState *state = ecs_get_mut(ECS, entity, BzBTState);

View File

@@ -239,14 +239,16 @@ void entityUpdate(ecs_iter_t *it) {
void entityMoveToTarget(ecs_iter_t *it) {
Position *position = ecs_field(it, Position, 1);
Velocity *velocity = ecs_field(it, Velocity, 2);
HitBox *hitbox = ecs_field(it, HitBox, 2);
Velocity *velocity = ecs_field(it, Velocity, 3);
TargetPosition *targetPos = ecs_field(it, TargetPosition, 3);
Steering *steering = ecs_field(it, Steering, 4);
TargetPosition *targetPos = ecs_field(it, TargetPosition, 4);
Steering *steering = ecs_field(it, Steering, 5);
for (i32 i = 0; i < it->count; i++) {
Position target = targetPos[i];
steering[i] = Vector2Subtract(target, position[i]);
Vector2 center = entityGetCenter(position[i], hitbox[i]);
steering[i] = Vector2Subtract(target, center);
f32 dst = Vector2LengthSqr(steering[i]);
if (dst < 2.0f) {

View File

@@ -156,7 +156,7 @@ void inputUnitAction(Game *game, InputState *input) {
if (!hasNext) break;
Position target = *ecs_get(ECS, harvestEntity, Position);
f32 proximity = 6.0f;
f32 proximity = 8.0f;
if (resource.type == RES_FOOD)
proximity = 2.0f;

View File

@@ -180,7 +180,7 @@ void setupSystems() {
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
ECS_SYSTEM(ECS, entityUpdate, EcsOnUpdate, Position, HitBox, Velocity, Unit, Owner, SpatialGridID);
ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Velocity, TargetPosition, Steering);
ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, HitBox, Velocity, TargetPosition, Steering);
ECS_SYSTEM(ECS, entityMoveSwarm, EcsOnUpdate, Position, Velocity, HitBox, Swarm, Owner, Steering);
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path);

View File

@@ -137,9 +137,10 @@ void entityUpdate(ecs_iter_t *it);
/*
* 1: Position
* 2: Velocity
* 3: TargetPosition
* 4: Steering
* 2: HitBox
* 3: Velocity
* 4: TargetPosition
* 5: Steering
*/
void entityMoveToTarget(ecs_iter_t *it);