Extending Prop Sphere: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
 (Seperated the snippet block from Prop_sphere, and made it as a seperate snippet code, including a contribution on an issue with the latest 2013 Code, will have this be accessible from the prop_sphere page.)  | 
				m (Category addition.)  | 
				||
| Line 106: | Line 106: | ||
Contributor : [[User:Avanate|Avanate]]  | Contributor : [[User:Avanate|Avanate]]  | ||
[[Category:Programming]]  | |||
[[Category:Tutorials]]  | |||
Revision as of 12:10, 16 September 2018
The following simple snippet addition to CPhysSphere:
- Allows level designers to configure the collision model's radius
 - Fully applies the prop_data and $surfaceprop of the chosen model.
 
C++
Open \server\props.cpp and replace this current existing CPhysSphere code :
// Debug sphere
class CPhysSphere : public CPhysicsProp
{
	DECLARE_CLASS( CPhysSphere, CPhysicsProp );
public:
	virtual bool OverridePropdata() { return true; }
	bool CreateVPhysics()
	{
		SetSolid( SOLID_BBOX );
		SetCollisionBounds( -Vector(12,12,12), Vector(12,12,12) );
		objectparams_t params = g_PhysDefaultObjectParams;
		params.pGameData = static_cast<void *>(this);
		IPhysicsObject *pPhysicsObject = physenv->CreateSphereObject( 12, 0, GetAbsOrigin(), GetAbsAngles(), ¶ms, false );
		if ( pPhysicsObject )
		{
			VPhysicsSetObject( pPhysicsObject );
			SetMoveType( MOVETYPE_VPHYSICS );
			pPhysicsObject->Wake();
		}
	
		return true;
	}
};
With this improved version of the CPhysSphere code :
class CPhysSphere : public CPhysicsProp
{
	DECLARE_CLASS( CPhysSphere, CPhysicsProp );
	DECLARE_DATADESC();
public:
	float m_fRadius;
	bool CreateVPhysics()
	{
		SetSolid( SOLID_BBOX );
		SetCollisionBounds( -Vector(m_fRadius), Vector(m_fRadius) );
		objectparams_t params = g_PhysDefaultObjectParams;
		params.pGameData = static_cast<void *>(this);
		IPhysicsObject *pPhysicsObject = physenv->CreateSphereObject( m_fRadius, GetModelPtr()->GetRenderHdr()->textureindex, GetAbsOrigin(), GetAbsAngles(), ¶ms, false );
		if ( pPhysicsObject )
		{
			VPhysicsSetObject( pPhysicsObject );
			SetMoveType( MOVETYPE_VPHYSICS );
			pPhysicsObject->Wake();
		}
	
		return true;
	}
};
LINK_ENTITY_TO_CLASS( prop_sphere, CPhysSphere );
BEGIN_DATADESC( CPhysSphere )
	DEFINE_KEYFIELD( m_fRadius, FIELD_FLOAT, "radius"),
END_DATADESC()
After replacing the CPhysSphere code, remove this line :
LINK_ENTITY_TO_CLASS(prop_sphere, CPhysSphere);
That is located AFTER This block of code :
void CPropDoorRotating::InputSetSpeed(inputdata_t &inputdata)
{
	AssertMsg1(inputdata.value.Float() > 0.0f, "InputSetSpeed on %s called with negative parameter!", GetDebugName() );
	m_flSpeed = inputdata.value.Float();
	DoorResume();
}
As it then begins to create compile errors thanks to replacing the class CPhysSphere : public CPhysicsProp code.
Extended FGD
@PointClass base(BasePropPhysics, RenderFields) studioprop() sphere(radius) = prop_sphere : "Creates a perfect sphere."
[
	radius(float) : "Radius" : 12 : ""
]
Credits
Original Writer : Artfunkel
Contributor : Avanate