Ryan's Documentations - kreetin7/SuperHotClone2018 GitHub Wiki

How the NPCS shoot at the player

NPCBehavior.cs is put on the NPC so they can look at the player. This script does not spawn the bullets or keep track of the shooting timer, it just positions the NPC in the direction of the Player. It calculates the position of the Player using player.position and subtracts it by the transform.position of the NPC in order to get the distance between them. Quaternion Rotation and transform.rotation ared used to turn the NPC towards the player while keeping them standing in the correct position.

A raycast is drawn from the NPC towards the Player and only returns true when hitting an object tagged “Player”. When it returns true, it sends the Debug.Log that the player is in sight. It originally was supposed to also spawn the bullets after a timer was up ,but we decided to move the shooting mechanic into another script so that we wouldn’t cause a merge conflict.

NPCShoot.cs is the script that holds the shooting timer, spawns the bullets and creates the particle effect of the gun. There is a timer called npcShootTimer that is set at 120f and each update goes down by one. Once the npc’s timer is up and firepoint is still there, the npc will instantiate a bullet that follows the direction the NPC is facing. While the bullet gets spawned, the muzzle flash particle effect plays, too.