How to have smooth first-person tool/weapon animations?

So I’ve seen a lot of developers working on first-person shooters as of late, and I really wanna know how they got their animations to be so smooth. Here’s an example of what I’m talking about:

Are they actually just using animations and some APIs I don’t know about? I’ve never really worked with animations before, so I need a rough idea of what I’m getting into here.

2 Likes

My guess is that they use springs (not the constraint).

2 Likes

There’s a lot of methods. A lot of it is just doing fancy kinds of interpolation and math on the guns.

Either TweenService on joints, animations with easing styles, or lerping

1 Like

(Not involved with the making of the gun in-video)

When I see things like this here is what I see;

  • Tick/delta based animations
  • Gun wobble based on springs
  • Gun bobbing based on a sin/cos curve

Tick()/delta based animation

Tick is an incredibly useful little function it;

Returns the number of seconds that have elapsed since the UNIX epoch (January 1st, 1970), on your computer. (Documentation - Roblox Creator Hub)

This means that every time it is called, you are at a seperate point in time. This allows us to find something really useful; Delta

Delta is the time between the current and last time something is called, tick() is something that can use this, but it also comes in some in-engine functions such as RenderStepped.

By using Delta’s, you can create smooth animations that shouldn’t change based on framerate. At 30 fps, it should still function the same as 60 fps. (Although, it will appear smoother on 60fps.) This is how everything here is being handled. Either by using the tick() to calculate the delta, or by using the in-engine methods.

Gun Wobble based on springs

I’ve only been introduced to springs in the last few months and to be perfectly honest, I am not at all familair with them. There is however a really good article here, but I’ll try and give you the jist of how I understand how to do it.

The gun model is being told that it needs to get from its current position, to its scoped position. You could really easily make a linear animation that goes from A to B, which I believe they do in the reload animation. For some games this is fine, for others it seems a little janky.

When the player moves their camera, the gun is still technically in the same position, but they are being told to be offset by X amount, to simulate a spring. This is a clamp, and a lot of games use it. (Look at a sniper in a cod montage doing a 1020 nocope at some insane camera speed. The gun will stay in one spot until the camera stops moving.) The spring is solved for every delta to give us the offsets.

Gun bobbing

The gun is moving along a Sine/Cos curve, based on the velocity of the character. I believe its how the breathing animation is being done. The person who coded this has likely given 3 or 4 states,

  • Aiming
  • Walking
  • Running
  • Idle

In all 4 of these states, they have their own ranges that the horizontal and vertical bobbing can be. Aiming will have a really small range, so that the player stays really close to being on-target. Walking will have an increased horizontal range, to simulate the body placing one foot infront of the other. Running has an even further increase horizontal range and a greater vertical range. All the while, Idle will have a reduced horizontal and vertical range, but probably still a greater vertical range, for the player’s ‘breathing’ up and down.

This is a mix of tick() and velocity based equations, which are always between its respective 1 and -1. By using them to solve the equation, it looks incredibly smooth. If you’d like an example of this, go into phantom forces and go from walking, to sprinting, then walking to dolphin-diving/sliding. When performing the last action, you should notice that your arms are going left and right waaaaaaay faster than they would running or walking.

anyway

Hope that answers your question, (this was supposed to be a really short answer…) if theres anything I’ve not picked up on, let me know and I’ll tell you what I know.

15 Likes

Looks like TurboFusion V4, which uses custom “joint tweening” functions. Personally, I use Roblox’s animation editor and that’s it.

4 Likes

For gun bobbing, I’d reccomend Lissajous equations to be more specific.

9 Likes

oh you beauty! Why have I never heard of this before?

1 Like

I wouldn’t worry about making anything fancy. I have yet to see any of those games get over 10 players :roll_eyes: Just stick to simple stuff like lerp for smoothing ADS, springs are overused and a majority of people don’t like them or don’t even notice them.

2 Likes

Hey you’re using my gun kit awesome! To answer your question on how I make my animations smooth, a lot of it is what edenojack said. For the movement animations, to get them to “blend” together I basically use a formula like this: w=ax+by+cz. a, b, and c being coefficients that range from 0-1, and x, y, and z being vectors that represent the positions and orientations of each specific movement animation (idling, walking, running). w is the sum of those positions and orientation which gives one single position and orientation instead of multiple that I have to tween between. For gun momentum and recoil, I use springs. I update the raw positions and orientations of the momentum and recoil and then pass those to the recoil and momentum springs. For the final total position and orientation, I simply add up the movement cframe, momentum spring output, and recoil spring output, and apply it to the animation weld. That way I have less welds and even though it’s a little more computationally expensive it much better than having 15 different welds to worry about. Hope this helped!

9 Likes

I understand the math behind how you are adjusting the CFrames for smooth animations, but I’m confused how you can accurately find the target CFrames for aiming down a sight. Especially when each gun will have different sizes with scopes higher up on the gun and some guns not having scopes at all. How do you mathematically solve the desired CFrame of the welds of the arms to position the gun so that it aligns with the current camera, and is exactly in the middle of the screen?
And on a side note, are you welding the arms to the players head, and changing the C1 value of the neck joint to move it with the player’s camera?

You’re going to be doing some potentially complex math to find that, alot of it will be repetetive visual work if you’re using mesh parts, as their central position will not be the position of the reticle. A technique I know a few people used to use was having a long thin part represent the ads viewpoint, and then solve the distance between the guns default line of sight and this new position. This could be different using this framework though.

1 Like

Yeah, with TurboFusion’s gun kit, there are three main parts: the Handle, which determines how it’s held, the MainPart, which determines where the bullets go, and the AimPart, which determines where the camera goes when aiming down sights.

hm, perhaps changing where the aimpart is will be enough to work around this, just find the desired position and move it there.

Yeah, what Turbo’s kit does, I believe, is determine the offsets for all the gun parts using toObjectSpace and inserts welds. Then, by tweening the handle to the camera CFrame * the offset between handle and aimpart, it should move the whole gun as well. Like I said, I’m not exactly sure if this is how he does it, I haven’t used his kit in a while.