Fixing trigger gravity

From Valve Developer Community
Jump to navigation Jump to search
Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Underlinked - Logo.png
This article needs more Wikipedia icon links to other articles to help Wikipedia icon integrate it into the encyclopedia. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

Warning.pngWarning:This fix doesn't appear to work 100% of the time, use at your own risk.

Currently the trigger_gravity brush entity doesn't actually function properly.

To fix gravity triggers, navigate to triggers.cpp, around line 2651 you should find this:

class CTriggerGravity : public CBaseTrigger
{
public:
	DECLARE_CLASS( CTriggerGravity, CBaseTrigger );
	DECLARE_DATADESC();

	void Spawn( void );
	void GravityTouch( CBaseEntity *pOther );
};
LINK_ENTITY_TO_CLASS( trigger_gravity, CTriggerGravity );

BEGIN_DATADESC( CTriggerGravity )

	// Function Pointers
	DEFINE_FUNCTION(GravityTouch),

END_DATADESC()

void CTriggerGravity::Spawn( void )
{
	BaseClass::Spawn();
	InitTrigger();
	SetTouch( &CTriggerGravity::GravityTouch );
}

void CTriggerGravity::GravityTouch( CBaseEntity *pOther )
{
	// Only save on clients
	if ( !pOther->IsPlayer() )
		return;

	pOther->SetGravity( GetGravity() );
}

replace the whole class, functions and all with this:

class CTriggerGravity : public CTriggerMultiple
{
public:
	DECLARE_CLASS(CTriggerGravity, CTriggerMultiple);
	DECLARE_DATADESC();

	void Spawn( void );

	void StartTouch(CBaseEntity *pOther);
	void EndTouch(CBaseEntity *pOther);
};
LINK_ENTITY_TO_CLASS( trigger_gravity, CTriggerGravity );

BEGIN_DATADESC( CTriggerGravity )

	// Function Pointers
	DEFINE_FUNCTION(StartTouch),
	DEFINE_FUNCTION(EndTouch),

END_DATADESC()

void CTriggerGravity::Spawn( void )
{
	BaseClass::Spawn();
	InitTrigger();
	//SetTouch( &CTriggerGravity::GravityTouch );
}

void CTriggerGravity::StartTouch( CBaseEntity *pOther )
{
	// Only save on clients
	//if ( !pOther->IsPlayer() )
	//	return;

	pOther->SetGravity( GetGravity() );
}

void CTriggerGravity::EndTouch(CBaseEntity *pOther)
{
	// Only save on clients
	//if ( !pOther->IsPlayer() )
	//	return;

	pOther->SetGravity(1);
}

trigger_gravity should work fine now on players, but still won't change a physics object's gravity.