Day 28, Gun Implementation — Recoil, Debugging

Recoil in normal mode and FineSight mode

Within the shoot(), We are going to implement Recoil of gun system by writing a coroutine. First, I needed to set the Vector3 positions of RecoilBack and also for when FineSight RecoilBack. Current gun already have forces of recoil announced in the script. Thus, a simple, Vector3 recoilBack = new Vector3(currentGun.recoilActionForce, originPos.y, originPos.z); and its similar for the finesight but just changing the currentgun.Finesightforce, the y and z value to finesightOriginPos.y and z. The gun position value is changeable through the x value because I’ve already changed the position of the gun within the player by changing the value in the gun holder to make it face the same way as the player would.

Then, we input a if function to, if !isFineSightMode.
currentGun.transform.localPosition = originPOS;
while(currentGun.transform.localposition.x ≤ currentGun.recoilActionForce — 0.02f)
currentGun.transform.localposition = Vector3.Lerp(currentGun.transform.localposition, recoilBack, 0.4f);
yield return null;
… similar as above but changing by the finesightmode values.

this way, the 0.02f gives a little leeway to return. And so the gun position will move positive value (back towards the player in this case) and return to the original position value. And of course when this coroutine is run, it needs to have stopallcoroutines(); before to undo multiple coroutines running and messing with the value changes.

Also, within the script there was an error when the player Reloads, you switch to a finesightmode that stops the conflict in mode. So the Reload value gets stuck in true* incompleting the process and thus Fire does not initiate as it does so when !isReload. So in TryFire(), i need to add the value in input.Getbutton && !isReload, add CencelFineSight(); within the Fire();, TryFineSight() also needs to have in input button, &&!isReload, and create

private void CancelFineSight()
{if(isFIneSIghtMode) FineSight();}

This completes and blocks in changing of mode while trying to reload which then prevents the gun being able to shoot as reload value doesn’t get stuck at a value true.




Software Developer @ GameDevHQ

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

More JavaScript Basic things you should know as a web developer.

Angular New Project Boilerplate: Workspace, Unit testing, Pre-commits hooks ,Custom Library…

HTML Boilerplate

Load Testing Socket.IO Web Applications and Infrastructure

Basics of JavaScript Closures

Typescript, simple things you need to know

Migrating away from moment.js

Immutability in JavaScript

Open Call for p5.js Project Lead

A group of people around a table with laptops in thoughtful conversation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ji Soo Ahn

Ji Soo Ahn

Software Developer @ GameDevHQ

More from Medium

CS373 Spring 2022: Brock Moore Week 14

Zeppelin Impersonation in JDBC Connection to Trino/PrestoSQL

On Demand Medicine Delivery App Development

Is it needed for devs to know company mission?