
Player & Camera Movement
The player object always contains an empty pivot object which contains the main camera. If the mouse movement is directly applied to the camera it will cause the camera to move around about itself instead of the place. Therefore the camera is placed at an offset from the pivot point or the player. When the mouse inputs horizontal or vertical movement the pivot is rotated, rotating the camera with it. To include the mouse and keyboard-directed movement. The forward vector and right vector are taken from the camera and input of forward/backward and left/right is multiplied to the respective vectors. The sum of these two vectors will accurately provide the player's desired location. Then the vector is normalized in values of 1 and -1 depending on the previous signs. With normalization, only the direction is extracted and direction * player's speed / % of player's mass is the model's new velocity.
Shooting a projectile
Projectile shooting is simple done by taking the player's forward position and adding 50% of the player's X-Box length to avoid the projection hitting the player itself. This direction is then normalized and the projectile's velocity is set. This V is not changed and the projectile keeps on travelling in the same direction unless it hits a food object in which it bounces off using unity's physics for 3 seconds and then auto-destruct. Hence any enemy is the projectile's collider during the 3 seconds is destroyed.
Enemy movement
Every frame the velocity of the enemy is the player's current position minus its position. This value is then normalized to provide the player's direction from the enemy's current position and it is moves towards the player a fixed velocity randomly chosen upon spawning between 1 to 5.