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

@@ -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) {