Multiplayer Shooter
-------------------------------------------------------------------------------------------------------------
In the past four weeks I have been working on a small multiplayer fps game. We had to make this game to try out some new things like raycasting and light baking. This project will show the things I learned while working on this project.
-----------
The Map
I made the models in the map using blender and made it so I can easly change the objects on the map if I would like to change the layout. The outside of the map was made with the Unity terrain editor. I used this because it makes the placing of trees easier and I was a able to deform the ground a bit so the outside wouldn't be the same everywhere.
----
Most of the light on the map is baked to reduce the draw calls and thus making the game easier to run. For the light on moving objects I used light probes.
------------------------------------------------------------------------------------------------------------------------
Joining the game
joining a team and storing the teams happens in the GameController this is a singleton meaning that it will always excist. This is good because if you want to have multiple maps the teams will stay the same between them.
----
When a player shoots the green join cube the following happens:
- The gamecontroller looks what team has the least players in it.
- It adds the player to the list of the team with the least players.
- It runs the RpcJoinTeam function on the player which changes the 
color of the player and sets the spawn position.
- It sets the detection on the shooting script so the player can only shoot the enemy.
- It spawns the player on the spawn on the playing field.
------------------------------------------------------------------------------------------------------------------------
Shooting
The model of the gun was made in Blender and for the animation I used the unity animator. when you run out of ammo you can press R to reload. This starts the animation and plays the reload sound. after the animation is finished it adds 10 ammo.
The shooting in the game is done using a raycast. This allows for fast and accurate hit detection. 

When the player clicks it runs the CmdShoot function. The script spawns a raycast from the camera going forward with a little bit of spread to recreate the feeling of recoil. if you hold the shoot button the recoil becomes worse with every shot and if you let go of the button it resets.

The raycast returns true if it hits something and looks what the raycast hit. If it hit an object with the "JoinButton" tag it adds the player to a team this if for the lobby. When the raycast hits a collider with the enemy tag which is set when joining a team it runs the RpcKillEnemy function which spawns in blood particles. It also applies the damage to the player you hit.
When you shoot the game also enables a line render this is the line you see ingame. If the raycast hits an object it enables the line renderer and sets the end position on the place the raycast hit the object. if the raycast doesn't hit an object it sets the end position of the line in front of the gun so you still see where you shot.
------------------------------------------------------------------------------------------------------------------------
Video
1v1 shooter
Opublikowano:

1v1 shooter

In the past four weeks I have been working on a small multiplayer fps game. We had to make this game to try out some new things like raycasting a Rozwiń

Opublikowano:

Dziedziny