Skip to content

Commit

Permalink
Merge pull request #2478 from nheir/fix/541
Browse files Browse the repository at this point in the history
fix #541 : remove weak hook using
  • Loading branch information
oy committed Aug 2, 2020
2 parents 293209e + 1894f14 commit ca5cb2a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,8 @@ void CGameClient::OnPredict()
if(!World.m_apCharacters[c])
continue;

World.m_apCharacters[c]->AddDragVelocity();
World.m_apCharacters[c]->ResetDragVelocity();
World.m_apCharacters[c]->Move();
World.m_apCharacters[c]->Quantize();
}
Expand Down
22 changes: 17 additions & 5 deletions src/game/gamecore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void CCharacterCore::Reset()
{
m_Pos = vec2(0,0);
m_Vel = vec2(0,0);
m_HookDragVel = vec2(0,0);
m_HookPos = vec2(0,0);
m_HookDir = vec2(0,0);
m_HookTick = 0;
Expand Down Expand Up @@ -327,15 +328,12 @@ void CCharacterCore::Tick(bool UseInput)
if(Distance > PHYS_SIZE*1.50f) // TODO: fix tweakable variable
{
float Accel = m_pWorld->m_Tuning.m_HookDragAccel * (Distance/m_pWorld->m_Tuning.m_HookLength);
float DragSpeed = m_pWorld->m_Tuning.m_HookDragSpeed;

// add force to the hooked player
pCharCore->m_Vel.x = SaturatedAdd(-DragSpeed, DragSpeed, pCharCore->m_Vel.x, Accel*Dir.x*1.5f);
pCharCore->m_Vel.y = SaturatedAdd(-DragSpeed, DragSpeed, pCharCore->m_Vel.y, Accel*Dir.y*1.5f);
pCharCore->m_HookDragVel += Dir*Accel*1.5f;

// add a little bit force to the guy who has the grip
m_Vel.x = SaturatedAdd(-DragSpeed, DragSpeed, m_Vel.x, -Accel*Dir.x*0.25f);
m_Vel.y = SaturatedAdd(-DragSpeed, DragSpeed, m_Vel.y, -Accel*Dir.y*0.25f);
m_HookDragVel -= Dir*Accel*0.25f;
}
}
}
Expand All @@ -346,6 +344,20 @@ void CCharacterCore::Tick(bool UseInput)
m_Vel = normalize(m_Vel) * 6000;
}

void CCharacterCore::AddDragVelocity()
{
// Apply hook interaction velocity
float DragSpeed = m_pWorld->m_Tuning.m_HookDragSpeed;

m_Vel.x = SaturatedAdd(-DragSpeed, DragSpeed, m_Vel.x, m_HookDragVel.x);
m_Vel.y = SaturatedAdd(-DragSpeed, DragSpeed, m_Vel.y, m_HookDragVel.y);
}

void CCharacterCore::ResetDragVelocity()
{
m_HookDragVel = vec2(0,0);
}

void CCharacterCore::Move()
{
if(!m_pWorld)
Expand Down
5 changes: 5 additions & 0 deletions src/game/gamecore.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class CCharacterCore
vec2 m_Pos;
vec2 m_Vel;

vec2 m_HookDragVel;

vec2 m_HookPos;
vec2 m_HookDir;
int m_HookTick;
Expand All @@ -173,6 +175,9 @@ class CCharacterCore
void Tick(bool UseInput);
void Move();

void AddDragVelocity();
void ResetDragVelocity();

void Read(const CNetObj_CharacterCore *pObjCore);
void Write(CNetObj_CharacterCore *pObjCore);
void Quantize();
Expand Down
6 changes: 6 additions & 0 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ void CCharacter::TickDefered()
m_ReckoningCore.Quantize();
}

// apply drag velocity when the player is not firing ninja
// and set it back to 0 for the next tick
if(m_ActiveWeapon != WEAPON_NINJA || m_Ninja.m_CurrentMoveTime < 0)
m_Core.AddDragVelocity();
m_Core.ResetDragVelocity();

//lastsentcore
vec2 StartPos = m_Core.m_Pos;
vec2 StartVel = m_Core.m_Vel;
Expand Down

0 comments on commit ca5cb2a

Please sign in to comment.