Move towards center when harvesting resources

This commit is contained in:
2024-02-13 13:24:28 +01:00
parent acebdceb6c
commit 2c0ceb026b
4 changed files with 10 additions and 8 deletions

View File

@@ -17,8 +17,10 @@ float shortestArc(float a, float b) {
BzBTStatus aiMoveTo(AIBlackboard *data, f32 dt) {
Game *game = ecs_singleton_get_mut(ECS, Game);
const Vector2 pos = *ecs_get(ECS, data->entity, Position);
const HitBox hb = *ecs_get(ECS, data->entity, HitBox);
const Vector2 target = data->moveToPos;
f32 dst = Vector2Distance(pos, target);
Vector2 center = entityGetCenter(pos, hb);
f32 dst = Vector2Distance(center, target);
if (dst < data->proximity) {
ecs_remove(ECS, data->entity, Path);
return BZ_BT_SUCCESS;
@@ -31,7 +33,7 @@ BzBTStatus aiMoveTo(AIBlackboard *data, f32 dt) {
if (ecs_has(ECS, data->entity, Orientation)) {
Orientation *orientation = ecs_get_mut(ECS, data->entity, Orientation);
f32 currentAngle = *orientation;
f32 targetAngle = Vector2Angle(pos, target);
f32 targetAngle = Vector2Angle(center, target);
f32 dif = shortestArc(currentAngle, targetAngle);
dif = Clamp(dif, -1, 1) * dt * 10;
*orientation += dif;

View File

@@ -383,7 +383,7 @@ void loadMap(Game *game, const char *path, bool mainMenu) {
.harvestTarget = nearest.entity,
.harvestPos = nearest.pos
},
.proximity = 8.0f,
.proximity = 4.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 < 4.0f)
b->proximity = 4.0f;
if (b->proximity < 2.0f)
b->proximity = 2.0f;
}
BzBTState *state = ecs_get_mut(ECS, entity, BzBTState);

View File

@@ -155,10 +155,10 @@ void inputUnitAction(Game *game, InputState *input) {
if (!hasNext) break;
Position target = *ecs_get(ECS, harvestEntity, Position);
HitBox targetHB = *ecs_get(ECS, harvestEntity, HitBox);
target = entityGetCenter(target, targetHB);
f32 proximity = 8.0f;
if (resource.type == RES_FOOD)
proximity = 2.0f;
f32 proximity = 4.0f;
Worker *worker = ecs_get_mut(ECS, entity, Worker);
worker->carryRes = resource.type;