Skip to content

Commit

Permalink
introduce yet another version of speedtiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mwinkens committed Feb 11, 2025
1 parent c011b25 commit 36c4af7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
19 changes: 14 additions & 5 deletions src/game/client/prediction/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 14 additions & 5 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 36c4af7

Please sign in to comment.