changing phyboxes whilst retaining collisions

Good morning,

I’m currently working on a project to try and shrink props to half their size while retaining normal physics interactions.

My current procedure is to use physobj:getMesh to return a table of the props vertices, then converting them to local coordinates using the props massCenter as a reference, then multiplying the vectors by a scalar (0.5) and from there I’m kind of stumped.

I don’t know what the commands to actually rebuild the physboxes while retaining client-side prediction are. There’s very little documentation on the wiki on what a lot of the newer commands actually do so I’m looking for a little bit of assistance from other developers.

Ideally the new modified prop would be identical to an unmodified one, save for being half the size.

Any help is much appreciated. I’ve been searching these forums relentlessly.

I’ll post my code thus far when I get to a computer.

There is a prop resizer tool on workshop, you can just look how it does it.

The function I think you’re referring to is this: PhysicsFromMesh

The thing is though when dealing with PhysicsFromMesh in the past, I’d be using it too much and it would often enough crash the server. Not sure if it’s been fixed since…

Then again I was using it for pretty intense shit…

Yeah, PhysicsFromMesh is very crash-likely. You gotta use

This is what I use:

[lua]-- Entity meta
local meta = FindMetaTable( “Entity” )

– This thing is full of dark magic!
function meta:InitClippedPhysics( planes )
if ( !planes ) then error( “No planes defined” ) end

-- Init normal physics, to obtain MeshConvexes
self:PhysicsInit( SOLID_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )

local phys		= self:GetPhysicsObject()

local volume	= phys:GetVolume()
local mass		= phys:GetMass()

-- Clip convexes
local convexes	= phys:GetMeshConvexes()
local clipped	= physmesh.ClipMultiConvex( convexes, planes )

-- Init clipped physics
self:PhysicsInit( SOLID_VPHYSICS )

self:PhysicsInitMultiConvex( clipped )

self:EnableCustomCollisions( true )

-- Calculate new mass, based off changed volume
local phys	= self:GetPhysicsObject()
	phys:SetMass( mass * ( phys:GetVolume() / volume ) )

return clipped


Just replace “physmesh.ClipMultiConvex( convexes, planes )” with your own method to manipulate
the physics mesh.