Top Down Shooter

Rabies Simulator by danielRift (itch.io)

Player Movement

This script has the code that allows the player to move and contains the movement to a specific area on the screen to prevent the sprite getting stuck outside of sight of the player. Vector3 stores a position with x, y and z coordinates.

This script turns the player to point towards the mouse and reticule to allow them to face the enemy they are aiming at.

Bullet code

These scripts generate and program the movement and angle of the bullets.

Enemy spawning

The coroutine runs every 2 seconds to begin with and with each enemy spawned reduces to gradually increase the difficulty of the game – this can be seen on line 73 where 0.2f is subtracted from the timer. As more enemies are spawned the variety of enemy types increases this can be seen in the if statement on line 65. The spawn location of the enemies is randomised using a switch case which has 4 options each with a row of possible spawn locations that form a box around the camera so that enemies can spawn anywhere around the player offscreen.

enemy direction and movement

To make the enemy point towards the player I had to use the Math Atan2 function to calculate the angle that the enemy needs to face to be pointing at the player and then transform rotation changes the enemy’s direction to that angle.

Sound

The FMOD code play one shot triggers the forest ambience event once but as the FMOD file loops it plays the whole time the game is running.

The collision code is attached to the player and the player bullet and is activated whenever either of them collide with anything.

Leave a comment

Your email address will not be published. Required fields are marked *