From 18e308bd03401985d160623b29e6704592e1336e Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Sun, 2 Aug 2026 13:51:01 +0800 Subject: [PATCH] feat(gameplay): add pig wander AI and refine speed physics --- src/gameplay/server_entity_manager.cpp | 6 +++--- src/gameplay/systems/speed_system.cpp | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gameplay/server_entity_manager.cpp b/src/gameplay/server_entity_manager.cpp index 222d792..c87ae82 100644 --- a/src/gameplay/server_entity_manager.cpp +++ b/src/gameplay/server_entity_manager.cpp @@ -20,9 +20,9 @@ void ServerEntityManager::init() { m_factories.try_emplace("cubed:pig", [this]() { BaseServerCreature c; c.hitbox = HitboxManager::instance().get_hitbox_id("cubed:pig"); - return create_entity_in_factory(Entity{m_next}, - EntityInfo{"cubed:pig", ""}, - std::move(c), PigTag{}); + return create_entity_in_factory( + Entity{m_next}, EntityInfo{"cubed:pig", ""}, std::move(c), PigTag{}, + AIBase{}, WanderAITag{}, MoveBoost{}); }); } void ServerEntityManager::update() { diff --git a/src/gameplay/systems/speed_system.cpp b/src/gameplay/systems/speed_system.cpp index 5f94e7f..ae7c202 100644 --- a/src/gameplay/systems/speed_system.cpp +++ b/src/gameplay/systems/speed_system.cpp @@ -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); } }