Remove player pushack: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(Removed pov)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
In this tutorial i will show you how to remove the push back velocity when a player takes a hit.  
This tutorial demonstrates how to remove the "push back" velocity applied to players when they get hit.
[[File:Nopushback.gif|thumb]]
[[File:Nopushback.gif|thumb]]
This tutorial was made using Source SDKbase 2013 Multiplayer - the legacy version >_> not the team fortress 2 update.
This tutorial was made using {{src13mp|4}} (''NOT'' the {{tf2branch|4}})


To start open your game solution - find and open the player.cpp file and find the
# Open your game solution and navigate to {{path|player|cpp}}, then find {{code|preset=1|highlight=cpp|CBasePlayer::OnTakeDamage_Alive}} function (line 1708)
'''CBasePlayer::OnTakeDamage_Alive''' function around line 1708
# In the middle of this function around line 1736 lies this block of code:
 
<source lang=cpp>
in the middle of the function youll find this block of code below
if ( info.GetInflictor() && (GetMoveType() == MOVETYPE_WALK) &&  
[code]if ( info.GetInflictor() && (GetMoveType() == MOVETYPE_WALK) &&  
( !attacker->IsSolidFlagSet(FSOLID_TRIGGER)) )
( !attacker->IsSolidFlagSet(FSOLID_TRIGGER)) )
{
{
Line 15: Line 14:
force.z = 250.0f;
force.z = 250.0f;
}
}
//ApplyAbsVelocityImpulse( force ); drn0 disabled to remove pushback on hit
//ApplyAbsVelocityImpulse( force ); //drn0 disabled to remove pushback on hit
}[/code]
}
 
</source>
like so remove the call ApplyAbsVelocityImpulse( force ); from the end of the calculation


this removes the velocities resolution from the OnTakeDamage - but still Alive fuction
3. Remove the call to {{code|preset=1|highlight=cpp|ApplyAbsVelocityImpulse( force );}} from the end of the calculation. This will remove the velocity resolution from CBasePlayer::OnTakeDamage_Alive function leaving it to calculate and process still but not apply the pushback.


Then proceed towards line 5670 to find the void '''CBasePlayer::VelocityPunch( const Vector &vecForce )''' function
4. Then scroll down to line 5670 to find {{code|preset=1|highlight=cpp|void CBasePlayer::VelocityPunch( const Vector &vecForce )}}. In this function is this block of code :
within this youll find the code
<source lang=cpp>
void CBasePlayer::VelocityPunch( const Vector &vecForce )
void CBasePlayer::VelocityPunch( const Vector &vecForce )
{
{
// Clear onground and add velocity.
// Clear onground and add velocity.
SetGroundEntity( NULL );
SetGroundEntity( NULL );
//ApplyAbsVelocityImpulse(vecForce ); drn0 removing pushback on hit
//ApplyAbsVelocityImpulse( vecForce ); //drn0 removing pushback on hit
}
}
</source>


this is the initial velocity function to set the force applied at the time i believe so we remove that tihs too.
This is the initial velocity function to set the force applied at the time, remove this as well ({{code|preset=1|highlight=cpp|ApplyAbsVelocityImpulse( vecForce );}}). Without this removed, the maximum power of an hit causes the knockback to still occur{{confirm}}, so the removal of this function  removes the knockback indefinitely as well.  


go ahead and compile the solution - there shouldnt be any errors but if you get any let me know.
5. Compile the solutions - (there shouldn't be any errors but if you get any let [[User:DrN0|me]] know.)
now when you get hit you dont get magically slide backwards 2 arm lengths away - you just stand there and eat it.
Now when the player gets hit, he won't slide backwards 2 arm lengths away, he'll just stand there and eat it.
this was implemented in [https://store.steampowered.com/app/3418380/A%20Nights%20Haunting%20Source/ A Nights Haunting: Source]
This was implemented in [https://store.steampowered.com/app/3418380/A%20Nights%20Haunting%20Source/ A Nights Haunting: Source]

Latest revision as of 03:59, 27 June 2025

This tutorial demonstrates how to remove the "push back" velocity applied to players when they get hit.

Nopushback.gif

This tutorial was made using Source 2013 Multiplayer Source 2013 Multiplayer (NOT the Team Fortress 2 branch Team Fortress 2 branch)

  1. Open your game solution and navigate to 🖿player.cpp, then find CBasePlayer::OnTakeDamage_Alive function (line 1708)
  2. In the middle of this function around line 1736 lies this block of code:
if ( info.GetInflictor() && (GetMoveType() == MOVETYPE_WALK) && 
		( !attacker->IsSolidFlagSet(FSOLID_TRIGGER)) )
	{
		Vector force = vecDir * -DamageForce( WorldAlignSize(), info.GetBaseDamage() );
		if ( force.z > 250.0f )
		{
			force.z = 250.0f;
		}
		//ApplyAbsVelocityImpulse( force ); //drn0 disabled to remove pushback on hit
	}

3. Remove the call to ApplyAbsVelocityImpulse( force ); from the end of the calculation. This will remove the velocity resolution from CBasePlayer::OnTakeDamage_Alive function leaving it to calculate and process still but not apply the pushback.

4. Then scroll down to line 5670 to find void CBasePlayer::VelocityPunch( const Vector &vecForce ). In this function is this block of code :

void CBasePlayer::VelocityPunch( const Vector &vecForce )
{
	// Clear onground and add velocity.
	SetGroundEntity( NULL );
	//ApplyAbsVelocityImpulse( vecForce ); //drn0 removing pushback on hit
}

This is the initial velocity function to set the force applied at the time, remove this as well (ApplyAbsVelocityImpulse( vecForce );). Without this removed, the maximum power of an hit causes the knockback to still occur[confirm], so the removal of this function removes the knockback indefinitely as well.

5. Compile the solutions - (there shouldn't be any errors but if you get any let me know.) Now when the player gets hit, he won't slide backwards 2 arm lengths away, he'll just stand there and eat it. This was implemented in A Nights Haunting: Source