shooting in games

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

shooting in games

Post by sudi »

I guess everyone of u played a multiplayer fps. so u all know that when u shoot the bullet comes from ur gun and flys directly at ur crossair and when another player fires his gun the bullet comes from his gun. well right now i'm in the position of creating a game with fps elements and i'm really stuck with making that what i just explained. Because when i would fire the bullet from the gun on the 3dmodel i would have to set the camera into the same position....but then when the gun for example is carried at ur hips everyone else would look way bigger because the camera is not at the head. but when putting the cam at the head position and still firing from the hips i would have to do a raycast to get the first intersection point of the gun with the level and put the crossair to the appropriate position on the screen to make the cross usefull again.....all this sounds a little bit unstructured but i'm really tired right now and i hope someone knows a good and clean solution.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

Dont fire your bullet from your camera, fire it from your gun. :D
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

yeah...but then the bullet wont fly stright at the position were the crossair points at
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

Hmmmm I suppose, it all depends on what exactly you want.

You could cast a ray from a node that is an offset child of the character node and use the rotation of the gun as a vector.

Obviously though thats only any good if your gun isnt a separate node. It may be the case that the gun is actually part of the character.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

well the gun is an object....where i keep the mesh doesn't matter at all. but raycasting is time intense and when the server has to raycast for lets say 16 players he will kill himself.....
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

Not really. If you have a server running it, all you need to do is send positions and state data back to clients who then interpolate if needed. Casting rays is much better than making actually bullet meshes and firing them.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

no i mean raycasting to get the point the bullet will hit which would be done every frame no matter if there is a bullet or not
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
FlyingIsFun1217
Posts: 219
Joined: Fri Apr 13, 2007 8:29 pm
Location: Illinois
Contact:

Post by FlyingIsFun1217 »

I didn't read your post all the way, but if your trying to get the bullet path, just enter a path to check on the mouse click. See if it intersects anything.

FlyingIsFun1217
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

why ray casting? i am sure that all now days FPS games use physics engines, there is nowhere to go without them :) so if you shoot real bullet mesh you can do some actions on collision (newton has callbacks for that as far as i remember). Also shooting a bullet mesh would be much more realistic. we know that bullet does not come to target instantly so there is a chance to dodge flying bullet, but i don't know any FPS gamer who can dodge a ray that is already casted :) also bullet does not go just straight where your gun is pointed. It is affected by lots of natural causes (wind in egsample). This way must have disadvantages too, just i actually don't know them yet because i never implemented this kind of thing. Problem could be that fast flying bullet just goes through target without hitting it. That may happen because bullet position is calculated every frame and lets say in frame N bullet position is 2 units before target, in frame N+1 bullet position is 2 units behind target, then no actual collision happens. But if you use newton this should be fixed now, just SDK with patch is not released yet.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

i guess i 'm not good in explaining a problem
the problem is not the bullet or stuff like that
the problem is aiming and where the bullet starts and all that. If it would be single player....simple i only have one mesh. but my problem is that i have a server-client system
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
JRowe47
Posts: 55
Joined: Sat Jun 30, 2007 9:09 am

Post by JRowe47 »

What you want to do then is develop a coordinate system relative to the scene root, and an event flag, call it "bulletsFired", and send a vector representing the direction the bullet was fired and it's starting point to the server, and the time it was fired.

The server would take the vector and starting position, read the "bulletsFired" event, do the gameplay tests, like "is the player alive" and "does he have enough bullets" and "is a gun equipped" and things like that. If the bulletsFired event gets approved, then a flag is loaded into your network update packet and sent out to all the other players. From there, the server tests if anyone was hit by the bullet, or if geometry got in the way (curses! Eulered again!.) If someone was hit, then a "hasBeenHitByABullet" event is fired and again sent off.

Meanwhile, the clients take the "bulletsFired" event from the server packet and recreate the behavior... the original player's avatar fires a bullet, and the client tests for collision and all the rest.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

I can't be bothered to read/understand all the posts. But from what I gather...

From the collision/ray point of view, you just use the standard ray-from-camera-along-camera-vector-to-collision-point (from the scene collision manager or whatever). Now you have the shooting ray, starting at the camera and ending at the "Collision Point".

Then you only need the gun's ray to position any special effects (e.g. a muzzle flash...). This ray is simply ray from gun position to the Collision Point. (You might want to set the gun's angle to point along this vector for realism)

I doubt any FPS actually uses a simulated bullet with physics, or at least the path may be calculated taking into account wind/gravity etc, but not over time, it will be done instantly. Perhaps they have parabola-to-mesh collision functions.

EDIT: I think the significant thing is, you *do* send the bullet from the gun, however the gun should first be orientated to point at the crosshair target.
JRowe47
Posts: 55
Joined: Sat Jun 30, 2007 9:09 am

Post by JRowe47 »

What the crosshair target is relative to the gun and the eye are two entirely separate things, and depending on the distance from the player, can be extremely significant in terms of what the bullet hits.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

So that's why in reality guns are fired from the shoulder!
FlyingIsFun1217
Posts: 219
Joined: Fri Apr 13, 2007 8:29 pm
Location: Illinois
Contact:

Post by FlyingIsFun1217 »

roxaz wrote:why ray casting? i am sure that all now days FPS games use physics engines, there is nowhere to go without them.
Ummm, because I like my precious fps.
Use casting to get the path, send a quick bullet animation, see if the ray intersects.

Maybe I'm wrong on this one, but it seems like this would be altogether easier, and less CPU/GPU intensive. PLEASE CORRECT ME IF IM WRONG!

FlyingIsFun1217
Post Reply