December 2020
Posted 4 years ago
I really struggled with viewmodels. It seems overly complicated to me that the viewmodels are serverside, and they always exist, and we're changing the model when we change guns, but they're predicted and only ever seen by us.

So after a few days of trying to make it make sense, I made them totally clientside. My reasoning is that they should behave like a HUD, like they're drawn on the screen.

This has made things a billion times simpler.. and although there are things that I know we'll have to work around, it works exactly how I'd expect it to.

attribute 'contenteditable' not allowedattribute 'blocktype' not allowed
Please excuse the fact that you can see the shadow of the third person gun on the viewmodel.

Here's some code stuff.
attribute 'contenteditable' not allowedattribute 'blocktype' not allowedattribute 'data-image-style' not allowed
There's nothing magic or hidden about BaseViewModel, it exists in addon code. The property EnableViewmodelRendering can be set on any model and it basically marks it as a viewmodel - which means it'll only render if you're in first person and looking through one of its parents. It'll also render in the viewmodel path which stops it clipping through the walls.

The only thing really special about BaseViewModel is that I wired it up to get a call when we set the camera position, so it can position itself at the player's eyes.
attribute 'contenteditable' not allowedattribute 'blocktype' not allowedattribute 'data-image-style' not allowed