In week three we started doing something I've been looking forward to: first person shooters. Whilst we covered an Angry Birds style catapult system as well, the FPS mechanics are what I definitely want to use in my game, so learning about it helped me broaden my ideas for the mechanics I could use. We started the catapult/trajectory mechanic first, so I'll cover that to begin with. The objective was to create an object that, when the mouse was clicked and held, produced dots to show the trajectory of the object. Upon releasing the mouse button the object would be propelled along that path shown. In order to produce the trajectory, we needed to use two equations which calculated the distance the object traveled in both the x & y axis and project the dots along this path.
![]() |
Trajectory equation code |
For the first person shooter project we had to put a first person character controller into the scene and to that we attached a bullet script. This script very simply creates a bullet game object and applies an impulse force, which uses the objects mass and gives realism in the trajectory of the bullet. Initially the code was set to fire on every mouse click, which produces a semi-automatic gun. I changed mine to fire when the mouse button is down which creates a fully automatic gun, albeit an incredibly fast one which I'll need to tone down. To stop the scene from filing with useless bullets after they're fired, the bullets are set to be destroyed after 3 seconds. A pool manager would be far more useful and efficient so I'll work on that in my spare time.
![]() |
Bullet fire code |
In order to make the bullets fire from an appropriate position on the player, a gun script is needed which sets the firing position of the bullets to a specific place. In my case I used an empty game object attached to the right side of the player. This makes it look as if the player is firing a gun in their hands. For fun I added a second bullet spawn to the other side of the player to appear like the player is dual wielding the guns. These scripts are something I'll be playing around with a lot in order to get the best feel for my guns in my game.
Shooting block tower |
No comments:
Post a Comment