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;