Skip to content

[ALL] Expose VPhysics related functions#1891

Open
ALIEN31ITA wants to merge 2 commits intoValveSoftware:masterfrom
ALIEN31ITA:all-vphysics-vscript
Open

[ALL] Expose VPhysics related functions#1891
ALIEN31ITA wants to merge 2 commits intoValveSoftware:masterfrom
ALIEN31ITA:all-vphysics-vscript

Conversation

@ALIEN31ITA
Copy link
Copy Markdown

@ALIEN31ITA ALIEN31ITA commented Apr 17, 2026

Description

This Pull Request goal is to make Physics functions exposed to vscript, allowing mappers and scripters to experiment with any entity they wish, by turning them Physical, override their material properties, changing mass, making them float on water and so on.

All the functions should also work on brush entities too! (tested with CreatePhysics, and Setmass for now

API

Function Info
void CreatePhysics( int nSolidType, int nSolidFlags, bool asleep ) Create the entity Physics.
void DestroyPhysics() Destroy the entity Physics.
bool HasPhysics() Check if the entity has Physics.
int GetSurfaceProperty() Returns the ID of the entity's surfaceprop
string GetSurfacePropertyName(string name) Returns the ID of the name of the entity's surfaceprop
void SetSurfaceProperty( int surfaceprop ) Sets the ID of the entity's surfaceprop
void SetSurfacePropertyByName( string name ) Sets the ID of the entity's surfaceprop by name
void GetMass() N/A
float SetMass( float mass ) N/A
float SetBuoyancy( float buoyancy ) Sets the Buoyancy of the Entity, on a 0-1 ratio, 0 = sinks, 1 = fully float
void GetElasticity() N/A
float SetElasticity( float elasticity ) N/A
void ToggleCollisionsOn( handle entity, bool Enable ) Toggles collisions between 2 objects like logic_collision_pair, must use false, true only for colliding them again.
void SetPhysicsFlag( int PhysFlag ) Sets a Physics Flag to the entity
bool HasPhysicsFlag() checks a Physics Flag on the entity, usefull for detecting if 2 props are stuck into each other for example.
void RemovePhysicsFlag( int PhysFlag ) Remove a Physics Flag on the entity.

Showcase (of the Most important ones)

sv_turbophysics was turned off for demonstrating this in TF2.
It's kinda hard showcasing demostrating most of them, but i recorded the ones i find to be the most important, and a must have.

MakePhysics(6,0,false)

This is really usefull if you want to convert stuff to have physics, could be an NPC, or specific objects you wish, without requiring you to spawn a prop_physics (or anything physical) and parent it, should work with most entities.

2026-04-17.22-00-15.mp4

GetMass & SetMass

2026-04-17.22-00-25.mp4

ToggleCollisionsOn( used a loop in the example )

The Closest we have is using a logic_collision_pair, or setting the entities collisiongroup to COLLISION_GROUP_BREAKABLE_GLASS, but this gives us filtering, so we decide what to collide with or not (may not work on some entities).

2026-04-17.22-01-10.mp4

GetSurfacePropertyByName & SetSurfacePropertyByName

Let's you override their physical properties without the need of recompiling existing models.

2026-04-17.22-01-33.mp4

I will try Expose more functions, i only found these to be high priority, and easier to make accessible, if anyone has suggestions, or functions that SHOULD be exposed, or want to improve it, let me know.

This is very usefull, such as FVPHYSICS_PENETRATING, to find out if 2 props are stuck into each other (if not asleep)
Comment on lines +1512 to +1521
void ScriptSetElasticity( float flElasticity )
{
SetElasticity( flElasticity );
}

float ScriptGetElasticity ( void ) const
{
return m_flElasticity;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it is fine but you don't really need to make an wrapper for GetElasticity and SetElasticity since you can just directly define them as VScript functions. Just saying.

Copy link
Copy Markdown

@practicemedicine practicemedicine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a little comment around L1512-L1521 regarding how VScript functions are defined, but overall this looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants