Use center position for path following, tweak proximity threshold
This commit is contained in:
@@ -383,7 +383,7 @@ void loadMap(Game *game, const char *path, bool mainMenu) {
|
|||||||
.harvestTarget = nearest.entity,
|
.harvestTarget = nearest.entity,
|
||||||
.harvestPos = nearest.pos
|
.harvestPos = nearest.pos
|
||||||
},
|
},
|
||||||
.proximity = 3.0f,
|
.proximity = 8.0f,
|
||||||
});
|
});
|
||||||
Worker *worker = ecs_get_mut(ECS, workers[i].entity, Worker);
|
Worker *worker = ecs_get_mut(ECS, workers[i].entity, Worker);
|
||||||
worker->carryRes = resType;
|
worker->carryRes = resType;
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ void setAIBehaviour(ecs_entity_t entity, const BzBTNode *root,
|
|||||||
if (blackboard) {
|
if (blackboard) {
|
||||||
AIBlackboard *b = ecs_get_mut(ECS, entity, AIBlackboard);
|
AIBlackboard *b = ecs_get_mut(ECS, entity, AIBlackboard);
|
||||||
*b = *blackboard;
|
*b = *blackboard;
|
||||||
if (b->proximity < 2.0f)
|
if (b->proximity < 4.0f)
|
||||||
b->proximity = 2.0f;
|
b->proximity = 4.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
BzBTState *state = ecs_get_mut(ECS, entity, BzBTState);
|
BzBTState *state = ecs_get_mut(ECS, entity, BzBTState);
|
||||||
|
|||||||
@@ -239,14 +239,16 @@ void entityUpdate(ecs_iter_t *it) {
|
|||||||
|
|
||||||
void entityMoveToTarget(ecs_iter_t *it) {
|
void entityMoveToTarget(ecs_iter_t *it) {
|
||||||
Position *position = ecs_field(it, Position, 1);
|
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);
|
TargetPosition *targetPos = ecs_field(it, TargetPosition, 4);
|
||||||
Steering *steering = ecs_field(it, Steering, 4);
|
Steering *steering = ecs_field(it, Steering, 5);
|
||||||
|
|
||||||
for (i32 i = 0; i < it->count; i++) {
|
for (i32 i = 0; i < it->count; i++) {
|
||||||
Position target = targetPos[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]);
|
f32 dst = Vector2LengthSqr(steering[i]);
|
||||||
|
|
||||||
if (dst < 2.0f) {
|
if (dst < 2.0f) {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void inputUnitAction(Game *game, InputState *input) {
|
|||||||
if (!hasNext) break;
|
if (!hasNext) break;
|
||||||
Position target = *ecs_get(ECS, harvestEntity, Position);
|
Position target = *ecs_get(ECS, harvestEntity, Position);
|
||||||
|
|
||||||
f32 proximity = 6.0f;
|
f32 proximity = 8.0f;
|
||||||
if (resource.type == RES_FOOD)
|
if (resource.type == RES_FOOD)
|
||||||
proximity = 2.0f;
|
proximity = 2.0f;
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ void setupSystems() {
|
|||||||
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
|
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
|
||||||
ECS_SYSTEM(ECS, entityUpdate, EcsOnUpdate, Position, HitBox, Velocity, Unit, Owner, SpatialGridID);
|
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, entityMoveSwarm, EcsOnUpdate, Position, Velocity, HitBox, Swarm, Owner, Steering);
|
||||||
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path);
|
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path);
|
||||||
|
|
||||||
|
|||||||
@@ -137,9 +137,10 @@ void entityUpdate(ecs_iter_t *it);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* 1: Position
|
* 1: Position
|
||||||
* 2: Velocity
|
* 2: HitBox
|
||||||
* 3: TargetPosition
|
* 3: Velocity
|
||||||
* 4: Steering
|
* 4: TargetPosition
|
||||||
|
* 5: Steering
|
||||||
*/
|
*/
|
||||||
void entityMoveToTarget(ecs_iter_t *it);
|
void entityMoveToTarget(ecs_iter_t *it);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user