Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/systems/maneuvering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,31 @@ void ManeuveringSystem::update(float delta)
if (combat.charge > 1.0f)
combat.charge = 1.0f;
}

// Without an impulse engine there is no per-frame velocity override to
// act as a natural speed cap, so enforce one here. Bleed velocity back
// to 0 at that same rate when not maneuvering.
if (!entity.hasComponent<ImpulseEngine>())
{
if (auto physics = entity.getComponent<sp::Physics>())
{
float cap_speed = std::max(combat.boost.speed, combat.strafe.speed);
if (cap_speed > 0.0f)
{
auto velocity = physics->getVelocity();
float speed = glm::length(velocity);
if (combat.boost.active != 0.0f || combat.strafe.active != 0.0f)
{
if (speed > cap_speed)
physics->setVelocity(velocity * (cap_speed / speed));
}
else if (speed > 0.0f)
{
float new_speed = std::max(0.0f, speed - cap_speed * delta * 2.0f);
physics->setVelocity(velocity * (new_speed / speed));
}
}
}
}
}
}
Loading