This member has provided no bio about themself...

Report RSS ScrGold/Coding: func_pushable speeds up player

Posted by on

Here is the Problem: If the player "uses" ( push USE-Key) on a func_pushable, he can speed up himself by strafing or he can push it very fast away ignoring friction of the entity. Here is my fix. New/changed entries are pink.

Open func_break.cpp and go to CPushable::Move:

void CPushable :: Move( CBaseEntity *pOther, int push )
{
entvars_t* pevToucher = pOther->pev;
int playerTouch = 0;

// Is entity standing on this pushable ?
if ( FBitSet(pevToucher->flags,FL_ONGROUND) && pevToucher->groundentity && VARS(pevToucher->groundentity) == pev )
{
// Only push if floating
if ( pev->waterlevel > 0 )
pev->velocity.z += pevToucher->velocity.z * 0.1;

return;
}

if ( pOther->IsPlayer() )
{
if ( push && !(pevToucher->button & (IN_FORWARD|IN_USE)) ) // Don't push unless the player is pushing forward and NOT use (pull)
return;
playerTouch = 1;
}

float factor;

if ( playerTouch )
{
if ( !(pevToucher->flags & FL_ONGROUND) ) // Don't push away from jumping/falling players unless in water
{
if ( pev->waterlevel < 1 )
return;
else
factor = 0.1;
}
else
factor = 1;
}
else
factor = 0.25;

pev->velocity.x += pevToucher->velocity.x * factor;
pev->velocity.y += pevToucher->velocity.y * factor;

float length = sqrt( pev->velocity.x * pev->velocity.x + pev->velocity.y * pev->velocity.y );

if ( length > MaxSpeed() ) //if ( push && (length > MaxSpeed()) ) <- this is the old entry. why no fricition (maxspeed) if player uses ( means "push = 0" ) the func_pushable? delete this!
{
pev->velocity.x = (pev->velocity.x * MaxSpeed() / length );
pev->velocity.y = (pev->velocity.y * MaxSpeed() / length );
}

if ( playerTouch )
{
if ( pevToucher->button & IN_FORWARD ) //we need this! without the entity doesnt stop when player halts. no player movement = no entity movement.
{
pevToucher->velocity.x = pev->velocity.x;
pevToucher->velocity.y = pev->velocity.y;
}

if ( (gpGlobals->time - m_soundTime) > 0.7 )
{
m_soundTime = gpGlobals->time;
if ( length > 0 && FBitSet(pev->flags,FL_ONGROUND) )
{
m_lastSound = RANDOM_LONG(0,2);
EMIT_SOUND(ENT(pev), CHAN_WEAPON, m_soundNames[m_lastSound], 0.5, ATTN_NORM);
// SetThink( StopSound );
// pev->nextthink = pev->ltime + 0.1;
}
else
STOP_SOUND( ENT(pev), CHAN_WEAPON, m_soundNames[m_lastSound] );
}
}
}

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Level
96%
Gamer
7
Avatar
Avatar
Last Online
Country
Germany Germany
Gender
Male
Friends
Become friends
Member watch
Follow
Blog
Browse
Blogs
Report
Report
Share
Got it!

We have recently updated our privacy policy and terms of use in-line with GDPR requirements. More Info?