Engine icon indicating copy to clipboard operation
Engine copied to clipboard

Triggerable model changes and animations for viewmodels

Open HugoBDesigner opened this issue 3 months ago • 0 comments

Currently, the way to change the viewmodel is very limited – you can set it up with VScript or commands, but there is no "direct" system to target it. Moreover, once the viewmodel is changed – and especially when it's applied to a custom weapon or other custom behavior – there is no system to play animations to it.

Ideally, there should be a centralized system – either an entity controller or a new VScript class, possibly both – that allows for mappers to change the player's viewmodels, hide them, play animations, and get information from it.

Here is one example of how I'm currently tackling it: I have the player grab a weapon_cubemap, and as a placeholder, I am using the weapons/v_portalgun.mdl model for it. To set up the correct viewmodel, I have a logic_auto that calls a script's Initialize function:

ViewModel <- null;
function Initialize() {
	ReplaceWeaponModel();
	ReplaceWeaponModel();
}
function ReplaceWeaponModel() {
	ViewModel = Entities.FindByModel(null, "models/shadertest/envballs.mdl");
	ViewModel.SetModel("models/weapons/v_portalgun.mdl");
}

And yes, calling the function twice is somehow required. Then, to run an animation, I have to first set it to idle, and only then I can play an animation – not doing so means the animation won't play until the previous sequence is finished, sometimes even seconds after it has "settled" into an idle animation.

function AnimateViewModel(_anim, _recurse = true) {
	if (ViewModel) {
		if (_recurse) {
			AnimateViewModel(ViewModel.LookupSequence("idle"), false);
			EntFireByHandle(self, "RunScriptCode", "AnimateViewModel(" + _anim + ", false)", 0.01, self, self);
		} else {
			ViewModel.SetSequence(_anim);
		}
	}
}
function DoFizzlerAnimation() {
	if (ViewModel) {
		AnimateViewModel(ViewModel.LookupSequence("fizzle"));
	}
}

And while the above system works, it seems to only play the animation continuously if the player is holding either action button (mouse1 or mouse2):

https://github.com/user-attachments/assets/3f4081ea-b07f-4297-b107-ef2a05461a4c

HugoBDesigner avatar Sep 14 '25 01:09 HugoBDesigner