Fixing trigger gravity: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Thunder4ik (talk | contribs) m (clean up, added orphan, underlinked tags) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Multiple issues| | |||
{{Underlinked|date=January 2024}} | |||
{{Orphan|date=January 2024}} | |||
}} | |||
=== {{warning|This fix doesn't appear to work 100% of the time, use at your own risk.}} === | |||
Currently the [[Trigger_gravity|trigger_gravity]] brush entity doesn't actually function properly. | Currently the [[Trigger_gravity|trigger_gravity]] brush entity doesn't actually function properly. | ||
To fix gravity triggers, navigate to triggers.cpp, around line | To fix gravity triggers, navigate to triggers.cpp, around line 2651 you should find this: | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
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 ) | void CTriggerGravity::GravityTouch( CBaseEntity *pOther ) | ||
{ | { | ||
Line 14: | Line 46: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
replace the whole class, functions and all with this: | |||
<syntaxhighlight lang="cpp"> | |||
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); | |||
} | |||
</syntaxhighlight> | |||
[[Trigger_gravity|trigger_gravity]] should work fine now on players, but still won't change a physics object's gravity. | [[Trigger_gravity|trigger_gravity]] should work fine now on players, but still won't change a physics object's gravity. | ||
[[Category:Tutorials]] |
Latest revision as of 22:42, 21 January 2024

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)

This article needs more
links to other articles to help
integrate it into the encyclopedia. Please help improve this article by adding links
that are relevant to the context within the existing text.
January 2024



January 2024

This article is an orphan, meaning that few or no articles link to it.
You can help by
adding links to this article from other relevant articles.
January 2024
You can help by

January 2024
Warning: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.