x


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).

more ▼

asked Jul 01 '10 at 11:19 AM

MikezNesh gravatar image

MikezNesh
843 64 74 93

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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...

more ▼

answered Jul 01 '10 at 01:23 PM

Novodantis 1 gravatar image

Novodantis 1
1.7k 14 22 40

Edited title like you said and yes yusing thumb stick and such.

Jul 01 '10 at 01:28 PM MikezNesh

How do you make the crosshair circle follow your movement?

Jul 01 '10 at 01:30 PM MikezNesh

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?

Jul 01 '10 at 01:31 PM MikezNesh

How should I do the raycast to shoot?

Jul 01 '10 at 01:43 PM MikezNesh

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?

Jul 01 '10 at 04:35 PM Novodantis 1
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5056
x1171
x274
x61
x10

asked: Jul 01 '10 at 11:19 AM

Seen: 1712 times

Last Updated: Jul 01 '10 at 01:27 PM