Animate arm movement when moving

This commit is contained in:
2024-01-07 09:01:33 +01:00
parent 8ff0078b70
commit 6884619f05

View File

@@ -146,7 +146,11 @@ static void entityUpdateArm(ecs_entity_t armEntity, Position pos, Velocity vel,
if (!armEntity) return;
const Arm arm = *ecs_get(ECS, armEntity, Arm);
Vector2 v = {arm.extended, 0.0f};
f32 time = fmod(GetTime() * 2.0f, 2.0f);
if (time > 1.0f) time = 2.0f - time;
f32 velLen = Clamp(Vector2Length(vel), 0, 4.0f) * time;
Vector2 v = {arm.extended, velLen};
v = Vector2Rotate(v, orient + arm.offset);
v = Vector2Add(v, pos);
ecs_set_ptr(ECS, armEntity, Position, &v);