Several titles have this:
Does anyone have any idea on how to do it? Doesn't seem like just a damp on mouse motion.
Several titles have this:
Does anyone have any idea on how to do it? Doesn't seem like just a damp on mouse motion.
That does seem to be a delayed camera response in the first video, the second doesn't seem to be showing that though. Rather the second video very specifically focuses on showing off, well as the video name says - animation - but also recoil.
Yes, but the recoil seems procedural, not animated in blender or something.
Here is what I think is happening in each of the videos. Just as an FYI, I have never worked on either of the games, and I am just guessing based on what I know, so I could (and probably am) be totally wrong on how they are handling the recoil/gun-sway :)
In the first video (TF2), here is what I think is happening.
The first thing I see is as Megalomaniak said, there is a bit of a delay between the camera movement and the model's movement. This is what is causing the model's hands to 'sway' around the screen. How this works is relatively simple:
You move the camera left/right with the mouse, and you move the model at a slightly slower speed. You check to see if the model's rotation is too far from the camera's rotation, and if it is, you quickly rotate it back within an acceptable range.
If you look carefully when the model is rotating and firing, you can see that the firing animation is playing which makes the gun move up and down and even a little to the sides. The reason I think this is an animation is because for a couple frames, you can see the model snap into the firing animation from the idle animation.
The animation is what is causing the recoil on the vertical axis, while the model's rotation is what is causing the majority of the recoil on the horizontal axis (some recoil is contributed from the animation).
For the bobbing when moving, this is because the entire first person model (in this case, the arms) is moving around at a slightly slower speed than the character controller. The idea works exactly the same as rotating the camera, but with a much smaller accepted range in comparison to the camera.
(These are just what I think is happening based on the video, and what I have played of TF2)
If I had to guess, I'd say they are using a IK system in the second video.
I would guess this for two reasons:
The first reason is because bullets in the second video come from the end of the gun, which has to be pointed at the target to fire at it. In TF2, the guns are always on the side, and so they can get away with some tricks, like making it look like it's firing from the end of the gun, but in actuality it's firing from a predefined point in the center of the player's camera. In the video above, if you watch the end of the gun when they are firing from the hip, the bullets hit the dirt more or less in line with the end of the gun.
Choosing way of handling the guns hints that they are using an IK system. One of the biggest reasons to fire bullets from the ends of the guns is because you want to allow for both aiming down the sights of the gun, and firing from the hip, all using the same code. The way you do this is by utilizing a IK system to handle the animations, because then all you have to do is move the IK point up and forward to look down the sights, while you have to move it back and rotate it slightly when firing from the hip.
Using a IK system allows for dynamic gun sway, because all you have to do is nudge the IK target slightly when a bullet is fired. This allows for different levels of recoil for each weapon, it allows for gun sway when taking damage (a common technique), and eases the work on the animation team.
There is a few drawbacks for using IK like in the second video, the biggest being it's hard to make the animations look good, especially if you need to rotate everything. For example, in the video above, did you notice that the majority of the time the guns are pointed forward, even when reloading? This is because of the IK system and the interesting challenges it presents when blending with static/pre-made animations.
(Once again, is just what I think is happening based on the video. I have not played the second game, so I am guessing purely based on what I can see in the video)
If you are trying to achieve gun sway/recoil that can be dynamically changed like in the second video above (and in other games like Destiny, Call of Duty, Battlefield) then I would highly suggest looking into using a IK system. Godot 3.1 is getting built in IK support, but you can also find a IK example written entirely in GDScript on the Godot demo repository (disclaimer: I wrote the example).
If you are looking to achieve a more controlled, predictable gun sway like in the first video above (and in other games like Doom, Quake, the older Halo games) then I would suggest making two models for your player: One being a 3rd person model for other players to see when playing the game, and a 1st person model (basically just arms and the gun) that the player sees when playing the game.
Thanks a lot for your insight and for distilling all this knowledge. Really appreciate it! :)