Facepunch / garrysmod-issues

Garry's Mod issue tracker
141 stars 56 forks source link

PhysicsInitConvex does not work clientside #5060

Open karolek471 opened 2 years ago

karolek471 commented 2 years ago

Details

Garry's Mod chromium branch Source Engine 24 build 8277.

Physics created with PhysicsInitConvex on server does not work on client. The clientside traces don't hit the entity. Can't use the properties menu ("C") on it. When the physics is created on both server and client the physgun grab becomes buggy but traces start to work.

Steps to reproduce

function ENT:Initialize()
    local mins, maxs = self:GetModelBounds()

    self:PhysicsInitConvex( {
        Vector( mins.x, mins.y, mins.z ),
        Vector( mins.x, mins.y, maxs.z ),
        Vector( mins.x, maxs.y, mins.z ),
        Vector( mins.x, maxs.y, maxs.z ),
        Vector( maxs.s, mins.y, mins.z ),
        Vector( maxs.s, mins.y, maxs.z ),
        Vector( maxs.s, maxs.y, mins.z ),
        Vector( maxs.s, maxs.y, maxs.z )
    } )

    self:EnableCustomCollisions( true )

    self:SetMoveType( MOVETYPE_VPHYSICS )
    self:SetSolid( SOLID_VPHYSICS )

    self:SetCollisionGroup(COLLISION_GROUP_PLAYER)

    local dist = mins:Distance(maxs)

    local phys = self:GetPhysicsObject()
    if(IsValid(phys)) then
        phys:SetContents(CONTENTS_SOLID)
        phys:SetMass(dist)
        phys:Wake()
    end
end
FlorianLeChat commented 2 years ago

This issue is also applicable to all physics initialization functions (ENTITY:PhysicsInit*) when the code is running clientside. However, a workaround is available here only for the movement issues.

karolek471 commented 2 years ago

that's a dirty solution but it works. thank you for help but it still would be cool if it would work properly

maurits150 commented 6 months ago

That dirty solution doesn't work entirely if you do want to initialize it clientside as well. The clientside prop likes to 'fall' despite having its position set every tick- it likes to simulate independently of server. That bug with the workaround can be worked around by freezing just the client physobj in place.

function ENT:Think()
    if CLIENT then
        local physobj = self:GetPhysicsObject()

        if IsValid(physobj) then

            physobj:EnableMotion(false)
            physobj:SetPos( self:GetPos() )
            physobj:SetAngles( self:GetAngles() )
        end
    end
end
Kefta commented 6 months ago

It sadly cannot be easily fixed because physobj info is not networked nor predicted. Most engine ents do not have clientside physobjs for this reason. The "hack" works well enough, though it should be done in a post-physics processing hook/callback rather than Think.