Week 2 - Playing around with physics and Raycasting

As a follow-on from the previous week some members of the group decided to develop a small Unity project designed to help us learn a bit more about Physics and physic materials as well as raycasting, including just using Unity to get used to it's basic features.

This led to the idea of a miniature version of a first-person shooter, with a basic plane in which a person is able to build things and blow things up. This chosen idea would allow the group to have a toy around with basic movement within a 3d space and how movement is applied when things like friction, gravity and mass are taken into account.

A key aspect of a first-person shooter is that the camera should always stay focussed on where the mouse is pointed. This was accomplished by first changing the camera position to be pointed to where the mouse currently resides within the screen window, then hiding the mouse. This is shown here:




The first attempt at movement consisted of taking the Horizontal and Vertical values of the Input from Unity and updating the player position by this amount, which resulted in some behaviours that were unwanted such as if the user were to stop adding movement whilst jumping, the player would stop mid air. As a result of this, we decided to toy around with applying force to a Rigidbody instead of simply updating it's position.

Adding force at first yielded unpredictable results and the player would not move in the direction the camera was pointed which was the intended outcome. This was overcome by adding force in the direction that the camera was facing instead as shown in this image:



The next part consisted of adding weapons to the game and a way of switching between weapons. It was decided that weapon switching would be accomplished using the middle mouse-button up and down, with left click being shoot. This required some weapons to actually shoot, so the first step was to create a weapon using basic shapes and have it fire other basic shapes. The code from previous in regards to pointing the camera was reused to be able to apply a force to the basic shapes being fired. After this the team had some fun toying around with weapons imported from the asset store, which had far more functionality to them such as sounds, animations and explosions to some of the weapons, as well as ammo and reloading.

All scripts relating to this project can be found at:  https://github.com/KAdams01/UnityFPS/tree/master/Scripts

Comments