I have implemented 2D shooting into the project, which will serve as the basis of our combat system. Enemies have yet to be added so the shooting cannot be made fully functional, but the foundation is there. Left clicking fires a projectile to the player's mouse position on the screen, allowing for very precise, skill-based combat. There is also a delay between shots rather than there being an infinite fire rate, forcing players to be careful about their shot placement. Everything about this system from the projectile movement speed to its fire rate can be easily adjusted via some public variables, allowing us to modify it as we go along.
Here are the variables in the player character script relating to the shooting system:
Here are the fire and reload functions from the player character script:
Here is the projectile script which causes them to destroy themselves when hitting something or after a set duration to stop them flying off forever if they miss:
Here's a video of the system in action:
Commenti