Add knockback when attacking, fix animation state

This commit is contained in:
2024-02-09 18:50:18 +01:00
parent 484e5e9b39
commit b8da0a9f2d
4 changed files with 28 additions and 17 deletions

View File

@@ -181,6 +181,8 @@ void entityUpdate(ecs_iter_t *it) {
continue;
}
f32 knockback = 1.0f;
// Attack update
if (canAttack && ecs_has(ECS, other, Health) && ecs_has(ECS, other, Owner)) {
Player otherPlayer = ecs_get(ECS, other, Owner)->player;
@@ -202,6 +204,8 @@ void entityUpdate(ecs_iter_t *it) {
canAttack = false;
unit[i].attackElapsed = 0.0f;
knockback = 3.0f;
}
}
@@ -209,6 +213,7 @@ void entityUpdate(ecs_iter_t *it) {
// Physics update
slowDown += 0.2f;
Position dif = Vector2Subtract(otherPos, position[i]);
dif = Vector2Scale(dif, knockback);
dir = Vector2Add(dir, dif);
}