Add knockback when attacking, fix animation state

This commit is contained in:
2024-02-09 18:50:47 +01:00
parent b8da0a9f2d
commit 2d08cf7b73

View File

@@ -181,7 +181,10 @@ void entityUpdate(ecs_iter_t *it) {
continue; continue;
} }
f32 knockback = 1.0f; // Physics update
slowDown += 0.2f;
Position dif = Vector2Subtract(otherPos, position[i]);
dir = Vector2Add(dir, dif);
// Attack update // Attack update
if (canAttack && ecs_has(ECS, other, Health) && ecs_has(ECS, other, Owner)) { if (canAttack && ecs_has(ECS, other, Health) && ecs_has(ECS, other, Owner)) {
@@ -204,17 +207,14 @@ void entityUpdate(ecs_iter_t *it) {
canAttack = false; canAttack = false;
unit[i].attackElapsed = 0.0f; unit[i].attackElapsed = 0.0f;
if (ecs_has(ECS, other, Velocity)) {
knockback = 3.0f; Velocity *otherVelocity = ecs_get_mut(ECS, other, Velocity);
*otherVelocity = Vector2Add(*otherVelocity, Vector2Scale(Vector2Normalize(dif), 4000 * dt));
}
} }
} }
// Physics update
slowDown += 0.2f;
Position dif = Vector2Subtract(otherPos, position[i]);
dif = Vector2Scale(dif, knockback);
dir = Vector2Add(dir, dif);
} }
if (stationary) { if (stationary) {