feat(gameplay): add pig wander AI and refine speed physics

This commit is contained in:
2026-08-02 13:51:01 +08:00
parent 2e4a32fed7
commit 18e308bd03
2 changed files with 18 additions and 5 deletions

View File

@@ -14,11 +14,24 @@ void SpeedSystem::update(float dt, entt::registry& registry) {
++moveboost.count;
creature.velocity.value +=
creature.direction.value * creature.movement.acceleration;
} else {
} else if (glm::dot(creature.velocity.value, creature.velocity.value) >=
0.001f) {
creature.velocity.value -=
creature.direction.value * creature.movement.deceleration;
} else {
creature.velocity.value = glm::vec3(0.0f);
}
creature.velocity.value.y = creature.gravity.value * dt;
creature.velocity.value.y += -creature.gravity.value * dt;
auto v_clamp = [](float& v, float max) {
auto temp = std::abs(v);
max = std::abs(max);
temp = std::clamp(temp, 0.0f, max);
v = temp;
};
v_clamp(creature.velocity.value.x, creature.velocity.max.x);
v_clamp(creature.velocity.value.y, creature.velocity.max.y);
v_clamp(creature.velocity.value.z, creature.velocity.max.z);
}
}