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

[Half-Life] Gargantua's Stomp attack is broken at higher framerates #2876

Open
BlackShadow opened this issue Mar 11, 2020 · 1 comment
Open

Comments

@BlackShadow
Copy link

BlackShadow commented Mar 11, 2020

Gargantua's stomp attack is broken at higher framerates because his attack movement/velocity based on framerate.

As it can be seen here: https://streamable.com/uajuq

To fix this:

halflife/dlls/gargantua.cpp

Lines 146 to 148 in c7240b9

// Accelerate the effect
pev->speed = pev->speed + (gpGlobals->frametime) * pev->framerate;
pev->framerate = pev->framerate + (gpGlobals->frametime) * 1500;

Change:

pev->framerate = pev->framerate + (gpGlobals->frametime) * 1500;

To:

pev->speed = pev->speed * 1.3;

@BlackShadow BlackShadow changed the title [Half-Life] Gargantua's Stomp attack broken in higher framerates [Half-Life] Gargantua's Stomp attack is broken at higher framerates Mar 11, 2020
@SamVanheer
Copy link

That doesn't really fix the problem. The attack speed will still be dependent on the framerate, just in a different way. Depending on the framerate the think method will execute more often since it can't execute exactly at the time set in pev->nextthink.

The proper way to fix this is to use the same solution as the turn rate fix (#2458).

After this line:

static CStomp *StompCreate( const Vector &origin, const Vector &end, float speed );

Add this:

int		Save(CSave& save) override;
int		Restore(CRestore& restore) override;
static	TYPEDESCRIPTION m_SaveData[];

float m_flLastThinkTime;

After this line:

LINK_ENTITY_TO_CLASS( garg_stomp, CStomp );

Add this:

TYPEDESCRIPTION	CStomp::m_SaveData[] =
{
	DEFINE_FIELD(CStomp, m_flLastThinkTime, FIELD_TIME),
};

IMPLEMENT_SAVERESTORE(CStomp, CBaseEntity);

Rework this code:

halflife/dlls/gargantua.cpp

Lines 124 to 148 in c7240b9

TraceResult tr;
pev->nextthink = gpGlobals->time + 0.1;
// Do damage for this frame
Vector vecStart = pev->origin;
vecStart.z += 30;
Vector vecEnd = vecStart + (pev->movedir * pev->speed * gpGlobals->frametime);
UTIL_TraceHull( vecStart, vecEnd, dont_ignore_monsters, head_hull, ENT(pev), &tr );
if ( tr.pHit && tr.pHit != pev->owner )
{
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
entvars_t *pevOwner = pev;
if ( pev->owner )
pevOwner = VARS(pev->owner);
if ( pEntity )
pEntity->TakeDamage( pev, pevOwner, gSkillData.gargantuaDmgStomp, DMG_SONIC );
}
// Accelerate the effect
pev->speed = pev->speed + (gpGlobals->frametime) * pev->framerate;
pev->framerate = pev->framerate + (gpGlobals->frametime) * 1500;

To this:

if (m_flLastThinkTime == 0)
{
	m_flLastThinkTime = gpGlobals->time - gpGlobals->frametime;
}

//Use 1/4th the delta time to match the original behavior more closely
const float deltaTime = (gpGlobals->time - m_flLastThinkTime) / 4;

m_flLastThinkTime = gpGlobals->time;

TraceResult tr;

pev->nextthink = gpGlobals->time + 0.1;

// Do damage for this frame
Vector vecStart = pev->origin;
vecStart.z += 30;
Vector vecEnd = vecStart + (pev->movedir * pev->speed * deltaTime);

UTIL_TraceHull( vecStart, vecEnd, dont_ignore_monsters, head_hull, ENT(pev), &tr );

if ( tr.pHit && tr.pHit != pev->owner )
{
	CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
	entvars_t *pevOwner = pev;
	if ( pev->owner )
		pevOwner = VARS(pev->owner);

	if ( pEntity )
		pEntity->TakeDamage( pev, pevOwner, gSkillData.gargantuaDmgStomp, DMG_SONIC );
}

// Accelerate the effect
pev->speed = pev->speed + deltaTime * pev->framerate;
pev->framerate = pev->framerate + deltaTime * 1500;

Instead of gpGlobals->frametime the code now uses the time between think method executions, which is the correct delta time. That time divided by 4 is a close enough match to the frametime at 30 FPS to consistently move the stomp at the same speed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants