Devlog #03 - Implementing Shooting [Part-A] - Mechanices Implemented
Introduction:
The next part of the plan is to implement shooting mechanics, which is the players' primary source of damage and, hence, winning. So, to add the shooting mechanics, the first thing to do is to position the placeholder gun on the placeholder arena player.
Attaching the Gun Model to the Player:

This is done by attaching the empty component called WeaponPos as a child to ArenaPlayer(placeholder player model). This is done to anchor the gun model on the player model and also instantiate the gun on that anchor point. So here, we assign our placeholder gun model as the starting weapon. This is checked at the start of the game to ensure the player starts with a gun, and we give the WeaponPos's (the empty child object) position and rotation as reference. Also, we have an object of type, a gun, to get the gun prefab and equipped as the starting weapon.

Also, the main purpose of the gun is to fire and attack. This is explained in the next section
Firing the gun:
The firing aspect of the gun is attached to a gun prefab, which, like the player model, requires an empty child object that could denote the spawn point of the bullets or projectile which is called ProjectileSpawn.

This part of the script is used to reference the projectile, the projectile's spawn point, and also determine the fire rate of the gun (which is how fast the projectile should spawn). Every time the shoot function is called, it instantiates a projectile prefab at the already given spawn point. This shoot function is called periodically (which is done by making the next time to fire equal to the sum of the current time and the fire rate).
The velocity of the projectile is programmed in the next section. However, the value of the velocity is passed from this script.

Velocity of projectile:
This script is a component of every new projectile instatiated through the script in the previous section. This script is used to determine how fast the projectile moves and what direction it follows. This is done using transform.Translate() function from unity
This script also contains a OnTriggerEnter() to determine any collision happening and destroy the bullet if it hits a wall.

Every time a player hits the button for shooting, it goes through all these scripts to make the shooting possible.


So with this, the basic shooting mechanics are done.
Aiming:
Now that the basic shooting mechanics have been implemented, it's time to direct where the bullet goes, a.k.a aiming. This is done using an aimcontroller script.
This is done by casting a ray from the camera to the mouse position or your cursor and converting them using ScreenPointToRay(). Once the ray hit, we could get the position of the mouse cursor as a vector 3 to make the player look at the cursor and also for the weapon model to look at the cursor.
But why make the gun model look at the Cursor?
So it could actually feel like aiming, and the precision matters here. Without making the gun look at the cursor, the player could have the mouse close to the player model and aim. But this is not something I wanted since now, having the gun look at the hit point or the mouse we require the player to actually keep the mouse on the enemy and if the player keeps it closer to the model the gun shoots at the floor.

Final Output:
The new problem with this:
Since I want the game to be compatible with both the keyboard and the gamepad. The new problem is how I could use a gamepad to control the mouse cursor. This is what's planned for the next devlog.
References:
[1] Unity Object.Instantiate: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Object.Instantiate...
[2] Unity Collider.OnTriggerEnter(Collider) : https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Collider.OnTrigger...
[3] Unity Camera.ScreenPointToRay : https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Camera.ScreenPoint...
Dice & Domination
Party board game
Status | In development |
Author | Akhil Mathew |
Genre | Strategy |
More posts
- Devlog #07 - Multiplayer Battle Mode Implemented2 days ago
- Devlog #06 - Implementing Enemy Turret2 days ago
- Devlog #05 - Implementing Health and Damage System8 days ago
- Devlog #04 - Implementing Shooting [Part-B] - Crosshair Implemented10 days ago
- Devlog #02 - Implementing Dash Mechanics38 days ago
- Devlog #01 - New Input Manager43 days ago
Leave a comment
Log in with itch.io to leave a comment.