Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #541 : remove weak hook using #2478

Merged
merged 5 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,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 @@ -65,6 +65,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 @@ -326,15 +327,12 @@ void CCharacterCore::Tick(bool UseInput)
if(Distance > PhysSize*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 @@ -345,6 +343,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 @@ -150,6 +150,8 @@ class CCharacterCore
vec2 m_Pos;
vec2 m_Vel;

vec2 m_HookDragVel;

vec2 m_HookPos;
vec2 m_HookDir;
int m_HookTick;
Expand All @@ -172,6 +174,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 @@ -556,6 +556,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