garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

Tool ghost entity improvements

Open Down-s opened this issue 4 years ago • 5 comments
trafficstars

I have fixed the jittering ghost entities for tools when you move them about, this happens because it's being updated in a TOOL:Think function, which isn't called at the client's FPS. I have moved the update ghost entity function for each tool into a TOOL:DrawHUD function, which is called every frame. I have also made balloons align with the surface normal, which feels more natural.

Before: https://user-images.githubusercontent.com/53242610/121425487-5da8ec00-c96a-11eb-89f6-5ae62ad4ab38.mp4

After: https://user-images.githubusercontent.com/53242610/121425559-731e1600-c96a-11eb-84ee-0a4c8ea8d8a1.mp4

Down-s avatar Jun 09 '21 20:06 Down-s

This breaks the ghost in single-player due to it existing as a serverside entity, not a clientside one.

Kefta avatar Jun 09 '21 22:06 Kefta

This breaks the ghost in single-player due to it existing as a serverside entity, not a clientside one.

Ah you are right, is there any reason it's a serverside entity when in singleplayer?

Down-s avatar Jun 09 '21 22:06 Down-s

It could have been a choice made before Garry added the hack to Think to be called shared in single-player, or maybe some CSEnt behaviour was broken in SP at one point. Either way it's too late to change now since some custom tools access the variable directly in a specific realm. Also, SWEP:DrawHUD is not going to be called if cl_drawhud is 0. You could instead use a Think hook which is called every frame on the client as opposed to being tied to server ticks.

Kefta avatar Jun 10 '21 02:06 Kefta

Would putting the update ghost entity function inside of a Think hook be a viable option?

function TOOL:Deploy()

    hook.Add( "Think", self, function()
        self:UpdateGhostBalloon( self.GhostEntity, self:GetOwner() )
    end)

end

Down-s avatar Jun 10 '21 14:06 Down-s

I wouldn't use self as the key since that has a higher chance of conflicting, but that is a valid solution.

thegrb93 avatar Jun 10 '21 19:06 thegrb93

Closing due to lack of activity.

robotboy655 avatar Jan 17 '23 19:01 robotboy655