How to handle gun shots?

Blitz3D Forums/Blitz3D Programming/How to handle gun shots?

gameproducer(Posted 2008) [#1]
Two questions:
1) What's the best way to handle bullets & shots?
2) ...what about in (online multiplayer) network game? :)

I'm back to using Blitz3D... and was searching for code on how to handle gun shots. Conclusion seems to be that linepicks should be avoided, and instead use bullets that collide... and do stuff depending on collision.

Here's some threads I've checked out:
http://www.blitzbasic.com/Community/posts.php?topic=76232#852521

damage effect:
http://www.blitzbasic.com/Community/posts.php?topic=76139#851176

line pick & slowdown:
http://www.blitzbasic.com/Community/posts.php?topic=75533#844735


I presume I should 'create bullet objects' and let them fly? Is this the most efficient way to handle them? (I expect to have single shooting guns, but also shotguns that could send 5-10 "bullets" per shot)

---

2) What about online play? (server-client)
Server is naturally in "right time", but all the clients lag behind (a bit), and their positions/rotations aren't exactly in sync.

Even though my game is not FPS, it still has enough shooting to make things bit more complex:
http://www.deadwakegame.com/forums/showthread.php?t=478 (link to a video showing shooting :))

I've dug some resources earlier, like this one:
http://www.gameproducer.net/2006/10/23/online-multiplayer-games-programming-resources-are-hard-to-find/
...but I think for example Valve's system (Source multiplayer) has too heavy calculation for figuring out "where client was aiming 200 milliseconds ago", and I'd try to look something bit more simple.

I *could* simply let client shoot (and lag behind), and then let server simply send "bullets info", but this still won't solve the problem if client was aiming to something that wasn't there.
(I suppose one idea could be to simply let client also 'decide' whether he 'clicked target', and then server would know too...)

Ideas?


Knight #51(Posted 2008) [#2]
Well for starters using Collisions,LinePick and all of those other things, will just make a big mess. To make this simpler (and mabey even faster) try this:


If EntityDistance("your bullets","your people") <= 1

   ;do whatever

EndIf




Nate the Great(Posted 2008) [#3]
If you don't have a lot of bullets at once then I would recommend linepicks because although they are slow, you only have to do 1 or 2 per frame which is not enough slowdown to matter.


Naughty Alien(Posted 2008) [#4]
..just include any of available physics engines and use raypicking and forget about speed issues..


mtnhome3d(Posted 2008) [#5]
first you clean the wound with antiseptic then bandage it up and then hope you don't bleed out till 9-1-1 arrives. :)
on topic:
i would do line picks and stagger the frames that you do the pick on, like frame1 bullets 1 and 2, frame 2 bullets 3 and 4 and so on an so forth.


Nate the Great(Posted 2008) [#6]
mtnhome3d

most of the time this isn't needed because it is unlikely that two bullets will be fired on the exact same frame but just in case it is good to include :)


Ross C(Posted 2008) [#7]
I agree with Naughty Alien. Use raypicking. It's hell of alot faster.


Knight #51(Posted 2008) [#8]
what is raypicking???


Nate the Great(Posted 2008) [#9]
or what is the difference between raypicking and linepicking besides speed ?


Gabriel(Posted 2008) [#10]
There is no difference between raypicking and linepicking, they are the same thing. The differentiation Naughty Alien was making is that when you do it with a physics engine, the calculations are very optimized. Physics engines tend not to deal with pure geometry. They see everything as a box, a cylinder, a sphere, or for more complex geometry, perhaps a convex hull. I can't personally confirm that it's faster than B3D picking, but I would certainly expect it to be.


Nate the Great(Posted 2008) [#11]
ok that always confused me until now thanks :)


Kryzon(Posted 2008) [#12]
I think the LinePicking speed depends a bit on the EntityPickMode set (as there is the polygon [SLOW], sphere [FAST] and bounding-box [FAST]). But still, making one line pick every time the user shoots is not at all time-consuming (what is time consuming is to use it every frame, like with towel-meshes. And that still runs pretty smooth for what it is). You really wouldn't be doing it every frame, only when the user shoots the gun. But if you're in doubt relating to CPU usage, go with a physics engine as it has not only really fast raypicking as also non-responsive collision detections and lots of other nice stuff adding capabilities to Blitz3D. You'll thank yourself.

And please don't use bullet models to check collisions...since when do we see a bullet flying through the air? if you make a nice barrel-flash, a nice shot sound and a nice impact, it makes no difference. Check counter-strike for example, uses no bullet models at all (I think you should only use bullet models when you are making cartoon games where you want that to happen. In realistic games that's just really unecessary).


Knight #51(Posted 2008) [#13]
ok........................what is linepicking????????????????


GIB3D(Posted 2008) [#14]
Linepicking = Picking pickable entities (use EntityPickMode) between two 3D points


Naughty Alien(Posted 2008) [#15]
..raypicking is way way faster than native B3D linepicking...Im using it as a part of my occlusion system, based on Physx..more than 3000 objects each frame picked in not time, less than 1 ms..when i tried to do same with standard B3D stuff, my frame rate simply...stuck..and my levels has 120K-200K polys...also, im using Physx for my characters collision and so on..simply..no slow down at all..


John Blackledge(Posted 2008) [#16]
Avoid EntityDistance except for the most coarse calculations.
As I found last night, if I shoot my man in the chest then EntityDistance effectively says the distance is 1.5 units/metres - from his chest to his feet, which is the origin point of the model.


Ross C(Posted 2008) [#17]
Yeah def. Entity distance is useful for stuff like coin collecting for example, where you don't want to actually register a coliision.


Knight #51(Posted 2008) [#18]
Yeah, I guess so.


gameproducer(Posted 2008) [#19]
Thanks guys. Especially the info about cleaning the wound with antiseptic first, then bandage it up and then hope you don't bleed out till 9-1-1 arrives was very helpful :)

RayPicking. I wonder if JVODE can handle that.
EDIT: just found there's a demo... next testing to see how fast it is....

----

Hmm, what about slow 'bullets'.... like, throwing a knife for example? :)


Kryzon(Posted 2008) [#20]
EntityCollided, EntityPick, LinePick (from the blade's beginning to it's tip).
You should filter your questions through common sense first...if you want to check if a line interesects a mesh, go with linepick. If you wanna check if a mesh intersected with a mesh, go with blitz collisions or EntityPick.


gameproducer(Posted 2008) [#21]
Uh... and Do'h. what were I thinking. :)'knife throwing' could indeed be done by checking "did it collide", and then check damage.

(well, in multiplayer it will require bit more than that... )


Kryzon(Posted 2008) [#22]
Sure, and then disabling the knife collisions and then parenting it to the target, so as the target moves the knife "sticks" to it :D