What is the best way to make a viewmodel animation?

I’m making a gun and I always wanted to try out ViewModel animating. What would be the best way and how would I do it? Heres what I want it to look like.

You can see how Ripull has a cool animation where if you move to the side, the gun kinda does the same. How would I recreate this?

@Ripull

1 Like

This is either done with an Animation Controller this allows non humanoid objects to play animations or its done with CFraming. The easiest method would be using an animation controller and animating the viewmodel with an humanoid in it (some animator plugins don’t work with a animation controller), after animating remove the humanoid (as the phyiscs the humanoid gives are prohibited) and add the controller.

3 Likes

I usually see people use the math.sin() function in conjunction with tick() to replicate that nice arm sway. Since sine returns an oscilating value no matter how high, it works perfectly with constantly rising values such as tick. No matter how high the value, it always translates to a certain angle on a circle, which means that as tick (elapsed time) climbs, sine function will make a nice oscilating number which can be used with cframes to achieve your desired effect.

The way I do it is have a base cframe of the viewmodel, and then I offset that by different cframe values with specific purposes.

local sway = CFrame.new(0,0,0) -- a value that is changing, lets say only on the x axis for simplicity's sake.
local baseCF = CFrame.new(0,1,0) -- represents a value for the default position of the viewmodel.

local function update()
viewmodel.CFrame = baseCF * sway -- set the viewmodel at the default position, offset by the sway value.
end
4 Likes

That video you linked was me learning how to originally make viewmodels.

This is a better example of one you’d probably want, the one in that video is really bad. https://www.youtube.com/watch?v=BD2v4aoJL9U

For breathing and swaying animations I use math.sin(tick()).
For specific animations I use a rigged viewmodel and Roblox animations.
For interpolation for animations and the viewmodels position I base it off of the clients framerate with segmented interpolation for players below 60fps.

There’s no easy way to do this by the way, my current viewmodel system is about 2000 lines of code.

Also I make my “Roblox” animations through blender and import them using Den_s’ plugin.

https://gyazo.com/e865ad9154aca4914de6f6eb070f02e9

14 Likes

Better to use Lissajous patterns for sway and breathing, which builds more on the sin, and introduces the cos, and then you can make very sweet movement patterns:

Mayhaps for breathing movement:

You can just plug in tick() as t

10 Likes

I love you for this :heart:

charrss

1 Like