Alongside animating the rifle I have also been creating the script for the player to move using the WASD keys, as well as making the mouse move the camera.

Mouse look

Fig 1: Variables used for the mouse look

As shown in fig 1 I have 4 variables that I am using for the mouse look. The idea for each variable is to allow me to change how fast players can move the camera while limiting how high and low they can turn the camera. This will prevent the camera and gun from clipping through the floor and through the ceiling. The final variable is mainly for smoothing the camera movement as without it the camera movement feels jittery.

Player movement

Fig 2: Variables used for player movement

As shown in fig 2 I have 3 variables for the player movement. The walk speed is how fast the player moves and the max walk speed is the speed cap the player can go to. The reason why I need a speed cap is because I am adding force to the rigidbody of the player character which means the player will gradually pick up speed when a movement key is held down.

The stop moving variable is used when the player does not have any movement key pressed down which stops the player gradually to a halt. Without this the player would increase their speed but when they let go of a movement key they would stop immediately no matter how fast they were going which looked odd.

Video Demonstration

Here is a demonstration of my player movement and mouse look code which has been uploaded to my YouTube channel. I will continue to upload to YouTube to show my progress as I go for scripting and animating.