Extending Prop Sphere

From Valve Developer Community
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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(), &params, 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(), &params, 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