This article's documentation is for anything that uses the Source engine. Click here for more information.

Prop sphere: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(removed a sentence for being completely false. also wondering if the entire TIP is necessary.)
No edit summary
 
(16 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Ent not in fgd|link=[[#Stock FGD|below]]}}
{{LanguageBar}}
{{Ent not in fgd}}
{{CD|CPhysSphere|file1=props.cpp}}
{{this is a|model entity|name=prop_sphere|engine=Source}}
It is essentially a [[prop_physics]] with a perfectly spherical [[VPhysics]] collision model of 12 units radius. If you want to create a spherical entity, it is far more efficient to use prop_sphere than try to create a spherical [[collision mesh]]!


{{point ent|prop_sphere}} It is not in any of Valve's FGDs, however.
{{tip|The only spherical model in Half-Life 2 is <code>models\combine_helicopter\helicopter_bomb01.mdl</code>.}}
 
{{confirm|Not all prop_physics KVs are applicable to this entity. Changing ''modelscale'' for example seems to produce effects with the physics.}}
It is essentially a [[prop_physics]] with a perfectly spherical [[VPhysics]] collision model. If you want to create an spherical entity, it is far more efficient to use prop_sphere than try to create a spherical [[collision mesh]]!
{{bug|The collision mesh will not be visible with the ''[[vcollide_wireframe]] 1'' command.}}


{{tip|The only spherical model in Half-Life 2 is <code>models\combine_helicopter\helicopter_bomb01.mdl</code>.}}
== Keyvalues ==


{{bug|The collision mesh will not be visible with the ''vcollide_wireframe 1'' command.}}
{{KV|Radius|intn=radius|float|The radius for the sphere.|only={{P2CE}}{{gmod}}}}


== Stock FGD ==
== FGD Code ==


If you don't intend to make any changes to the entity's C++ code, use this:
If you don't intend to make any changes to the entity's C++ code, use this:
Line 19: Line 23:
</source>
</source>


== Extending prop_sphere ==
== See also ==
 
* [[Extending_Prop_Sphere|Visit this snippet, on how you can improve the existing prop_sphere code.]]
The following simple addition to <code>CPhysSphere</code>:
* {{ent|prop_data}}
 
* [[Prop Types Overview]]
* Allows level designers to configure the collision model's radius
** {{ent|prop_physics}}
* Fully applies the [[prop_data]] and [[$surfaceprop]] of the chosen [[model]].
** {{ent|prop_physics_multiplayer}}
 
** {{ent|prop_physics_respawnable}}
=== C++ ===
** {{ent|prop_physics_override}}
 
** {{ent|prop_dynamic}}
Open \server\props.cpp and replace the existing <code>CPhysSphere</code> with this:
** {{ent|prop_static}}
 
** {{ent|prop_ragdoll}}
<source lang=cpp>
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()
</source>
 
=== Extended FGD ===
 
<source lang=ini>
@PointClass base(BasePropPhysics, RenderFields) studioprop() sphere(radius) = prop_sphere : "Creates a perfect sphere."
[
radius(float) : "Radius" : 12 : ""
]
</source>
 
== Stock Keyvalues ==
 
{{KV BasePropPhysics}}
{{KV RenderFields}}
 
== Stock Flags ==
 
{{Fl BasePropPhysics}}
 
== Stock Inputs ==
 
{{I BasePropPhysics}}
{{I RenderFields}}
 
== Stock Outputs ==
 
{{O BasePropPhysics}}


[[Category:Free source code]]
[[Category:Free source code]]
[[Category:Physics]]
[[Category:Physics]]
[[Category:Custom FGDs]]
[[Category:Custom FGDs]]
[[Category:Prop entities|sphere]]

Latest revision as of 02:24, 30 June 2025

English (en)中文 (zh)Translate (Translate)
Icon-NotInFGD.png
This entity is not in the FGD by default.
See below for instructions on making it available.
C++ Class hierarchy
CPhysSphere
CPhysicsProp
CBreakableProp
CBaseProp
CBaseAnimating
CBaseEntity
C++ props.cpp

prop_sphere is a model entity available in all Source Source games. It is essentially a prop_physics with a perfectly spherical VPhysics collision model of 12 units radius. If you want to create a spherical entity, it is far more efficient to use prop_sphere than try to create a spherical collision mesh!

Tip.pngTip:The only spherical model in Half-Life 2 is models\combine_helicopter\helicopter_bomb01.mdl.
Confirm:Not all prop_physics KVs are applicable to this entity. Changing modelscale for example seems to produce effects with the physics.
Icon-Bug.pngBug:The collision mesh will not be visible with the vcollide_wireframe 1 command.  [todo tested in ?]

Keyvalues

Radius (radius) <float> (only in Portal 2: Community EditionGarry's Mod)
The radius for the sphere.

FGD Code

If you don't intend to make any changes to the entity's C++ code, use this:

@PointClass base(BasePropPhysics, RenderFields) studioprop() = prop_sphere : "Creates a perfect sphere."
[
]

See also