Facepunch / garrysmod-issues

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

Velocity wrong on client inside CalcMainActivity #3322

Closed ZehMatt closed 3 years ago

ZehMatt commented 6 years ago

Details

The client for some reasons receives sometimes an vector length bigger than 0 when on some moving object. It will sometimes return 0 and sometimes the velocity of the move parent while the server value always sits at 0. This causes the players to go into the walk animation while they shouldn't.

Steps to reproduce

Put a bot on something moving like the train from d1_trainstation_01 and observe the velocity values on client and server.

Workaround

function GM:CalcMainActivity(ply, velocity)

    ply.CalcIdeal = ACT_MP_STAND_IDLE
    ply.CalcSeqOverride = -1
    self:HandlePlayerLanding(ply, velocity, ply.m_bWasOnGround)

    -- HACKHACK: People on moving platforms will moonwalk if we rely on then
    -- clientside velocity. Because clientside its an estimate we rather not
    -- use it.
    if SERVER then
        ply:SetNW2Vector("ActAbsVelocity", velocity)
    else
        velocity = ply:GetNW2Vector("ActAbsVelocity", velocity)
    end

    if (self:HandlePlayerNoClipping(ply, velocity) or
        self:HandlePlayerDriving(ply) or
        self:HandlePlayerVaulting(ply, velocity) or
        self:HandlePlayerJumping(ply, velocity) or
        self:HandlePlayerSwimming(ply, velocity) or
        self:HandlePlayerDucking(ply, velocity)) then
    else
        local len2d = velocity:Length2DSqr()
        if (len2d > 300) then
            ply.CalcIdeal = ACT_MP_RUN
        elseif (len2d > 1) then
            ply.CalcIdeal = ACT_MP_WALK
        end
    end

    ply.m_bWasOnGround = ply:IsOnGround()
    ply.m_bWasNoclipping = ply:GetMoveType() == MOVETYPE_NOCLIP and not ply:InVehicle()

    return ply.CalcIdeal, ply.CalcSeqOverride

end
Kefta commented 6 years ago

Does using GetAbsVelocity (actually binded to CBaseEntity::GetLocalVelocity) clientside not return the correct velocity?

mcNuggets1 commented 4 years ago

I actually opened up an issue about it affecting animations when being on platforms.

robotboy655 commented 4 years ago

Due to other players not being predicted and the fact that most of player related stuff like groundEntity and velocity is networked only to local player there really isn't a ready solution for this. Internally the engine just tries to estimate the velocity from 2 positions. (C_BaseEntity::EstimateAbsVelocity) This behavior should be identical to HL2DM, and probably TF2 as well.

ZehMatt commented 4 years ago

I think the velocity for players should not be estimated and rather be networked to all players, I proposed this to Willox a long time ago but he never really got around doing it.

robotboy655 commented 3 years ago

Should be fixed on Dev.