helix
helix copied to clipboard
Improvments to vendors PhysicsObjects and their collision
Calling PhysicsInit
while trying to create PhysicsObject
ends with it having invalid AABB if model is prop_ragdoll
, despite the entity itself having the valid ones. The result is simple - weird behaviour of vendors when they are being unfreezed and, for example, being knocked over.
The way to fix it is to use PhysicsInitBox
instead of PhysicsInit
, which adds another issue with bounding boxes being to big ignore the fact that they are remaining same even if entities angle is being changed. For example, you can just bump into invisible collision if vendor is 'lying' on a ground.
And this is where AddCallback
and OnAngleChange
come in, providing ability to change vendors collision bounds when angles is being changed.
As addition I want to mention, that currently, after changing vendors model, under certain circumstances you can unconsciously "unfreeze" vendor, because EnableMotion
and Sleep
is not being called after creating new PhysicsObject
.
I think everyone noticed this oddities with vendors and understand what I'm talking about, but if not, I can provide some screenshots of current problems and my fixes working fine.
I am having trouble understanding, could you like mspaint or give me a snippet to - see what you're talking about?
I am having trouble understanding, could you like mspaint or give me a snippet to - see what you're talking about?
In this video I've added this 2 lines in current ENT:Initialize
function:
print("Vendor Model Bounds: ", self:GetModelBounds())
print("Vendor Physics Object AABB: ", self:GetPhysicsObject():GetAABB())
And in this video I've changed this:
self:SetSolid(SOLID_BBOX)
self:PhysicsInit(SOLID_BBOX)
To this and used same prints I've writed above:
local mins, maxs = self:GetModelBounds()
self:PhysicsInitBox(mins, maxs)
And also added this, so when entities angles change collision bounds do not remain same:
self:AddCallback("OnAngleChange", function(entity)
local mins, maxs = self:GetModelBounds()
mins, maxs = self:GetRotatedAABB(mins, maxs)
entity:SetCollisionBounds(mins, maxs)
end)