This member has provided no bio about themself...

Report article RSS Feed ScrGold/Coding: func_pushable speeds up player

Posted by PanSartre on Jun 9th, 2013

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
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Level
93%
Gamer
7
Avatar
Avatar
Offline Since
Aug 15, 2014
Country
Germany Germany
Gender
Male
Member Watch
Track this member
Blog
Browse
Blogs
Report Abuse
Report article