From 36c4af7a82cb5395d4472b0f9f50a354c1785b9d Mon Sep 17 00:00:00 2001 From: Marvin Winkens Date: Tue, 11 Feb 2025 10:58:48 +0100 Subject: [PATCH] introduce yet another version of speedtiles --- .../client/prediction/entities/character.cpp | 19 ++++++++++++++----- src/game/server/entities/character.cpp | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index 4aa3e25304f..05aeff3e4cb 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -706,13 +706,22 @@ void CCharacter::HandleSkippableTiles(int Index) } else { - Force = minimum(Force, MaxSpeed); - TempVel += Direction * Force; - float NextSpeed = length(TempVel); - if(NextSpeed > MaxSpeed) + float DotProduct = dot(Direction, m_Core.m_Vel); + // project current speed onto speedup direction + vec2 Projection = Direction * DotProduct; // direction has length one + + // projection might point into opposite direction + int Sign = DotProduct < 0 ? -1 : 1; + float CurrentDirectionalSpeed = Sign * length(Projection); + float TempMaxSpeed = MaxSpeed / 5.0f; + //float SpeedupSpeed = length(Direction * Force); // direction has length one + if(CurrentDirectionalSpeed + Force > TempMaxSpeed) { - TempVel *= MaxSpeed / NextSpeed; + float NewForce = TempMaxSpeed - CurrentDirectionalSpeed; + TempVel += Direction * NewForce; } + else + TempVel += Direction * Force; } m_Core.m_Vel = ClampVel(m_MoveRestrictions, TempVel); } diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 88f1226bbf6..19a30e01b96 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1482,13 +1482,22 @@ void CCharacter::HandleSkippableTiles(int Index) } else { - Force = minimum(Force, MaxSpeed); - TempVel += Direction * Force; - float NextSpeed = length(TempVel); - if(NextSpeed > MaxSpeed) + float DotProduct = dot(Direction, m_Core.m_Vel); + // project current speed onto speedup direction + vec2 Projection = Direction * DotProduct; // direction has length one + + // projection might point into opposite direction + int Sign = DotProduct < 0 ? -1 : 1; + float CurrentDirectionalSpeed = Sign * length(Projection); + float TempMaxSpeed = MaxSpeed / 5.0f; + //float SpeedupSpeed = length(Direction * Force); // direction has length one + if(CurrentDirectionalSpeed + Force > TempMaxSpeed) { - TempVel *= MaxSpeed / NextSpeed; + float NewForce = TempMaxSpeed - CurrentDirectionalSpeed; + TempVel += Direction * NewForce; } + else + TempVel += Direction * Force; } m_Core.m_Vel = ClampVel(m_MoveRestrictions, TempVel); }