- Home /
Best way for setting up shooting mechanics for an FPS? (iPhone)
What would be the best way to set up shooting mechanics in a FPS? I know how to instantiate a bullet from a spawn point but...
How would you set up the little circle which signifies where you shoot at?
And how would you set the reloading mechanics?
(Please don't tell me to use the FPS game Unity provided because that doesn't work for Unity iPhone).
Answer by Novodantis 1 · Jul 01, 2010 at 01:23 PM
If this is for an iPhone then I recommend editing the question to include it in the title/tag, as it's pretty important.
I'm guessing you will use an on-screen thumb stick for movement and an on-screen button to shoot?
Firstly I would use raycasting for shots, unless you need to see the actual projectile, as physics is costly on the iPhone (I'm sure you know). The crosshair circle (where you aim) should be as simple as a GUI graphic in the center of the screen (unless we're firing something with gravity/bounce behaviour). Reloading can be simple as a value reset with sound effect, or can include an animation if the weapon is visible.
eg:
var ammunition:int = 200; var reload:boolean = false; var pressedReload:boolean var pressedFire:boolean // <- replace with whatever input is Fire
if (pressedFire && ammunition) { // <- play shoot sound here ammunition -= 1; // <- firing / hit testing code here } if (ammunition <= 0) { // <- play empty sound here ammunition = 0; reload = true; } if (pressedReload && reload) { // <- play reloading sound here ammunition = 200; reload = false; }
This is a very simple script, you can of course make many improvements (like a delay so reload is not instantaneous), but you get the idea from it...
Edited title like you said and yes yusing thumb stick and such.
How do you make the crosshair circle follow your movement?
How can I add it so the cross hair moves if I move my thumb stick? And how do I make the gun shoot aim at the cross hair circle?
Normally in an FPS the look control moves the camera, and the crosshair is fixed to the center of that. Unless we're talking more like an on-the-rails shooter, eg. Time Crisis?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
aiming at center of screen 1 Answer
What is wrong with this shooting script? 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Shooting Script Help 1 Answer