Game Development Community

Weapon fire detection in C++?

by Bryce "Cogburn" Weiner · in Torque Game Engine · 08/08/2004 (10:55 am) · 7 replies

I have a very specfic need and I was wondering if there was an object and method I could reference in the engine itself to detect if the weapon currently mounted on the control object has been fired.

If not I could either go round-a-bout in scripting calls (not as attractive) or alter the engine itself (just plain scarey).

Can I detect if the mounted weapon is in the recoil state? That would work just as well. How would I do that?

#1
08/08/2004 (11:41 am)
Well you could write a function in C++, expose it to the scripting language and in the onFire script call that function.
#2
08/08/2004 (11:59 am)
The problem is this is for a GUI control and must work in multiplayer...

Basically it's an implementation of a cone of fire system (ala Battlefield series). Using this resource as the inspiration, I've created a new crosshair GUI control that can expand and contract with scripting functions.

When a weapon is mounted, new parameters for the base size, maximum size, and expansion per shot are fed into the crosshair which automatically adjusts accordingly. All shots from the weapon are fired in a random vector but at their furthest point always fall within the cone.

... But I think I've just figured it out. If I add the current cone size to the shapeBase I can then have that information available on the client and the server, as well as for player mounted weapons and vehicle mounted weapons. At that point its academic since the crosshair GUI object on the client can access the shapeBase and modify itself accordingly. The behavior would then be similar to the GuiHealthBarHud object. The difference is cone of fire expansion occurs on recoil and retraction occurs at a timed interval on the client end (frame rate independant), so the GUI object will need to interface w/ the controling object to update the cone of fire reduction on the server.

Problem solved.

If anyone is willing to help get it "Torque Community Ready", I will probably finish this tonight and would like to contribute it as a resource. Right now the crosshair is a collection of dglDrawLine's and could certainly be made into a bitmap array, but that takes more Torque wisdom than I posses. If there are any interested parties please post here and when I'm done I'll email a copy for your perusal and correction.
#3
08/08/2004 (3:44 pm)
I tried the shapeBase route, but that just hardlocked the game as soon as the control was first rendered.... Not good.

I reverted my code and went 100% the way that Harold described. There's got to be a better way.... but it works.

Now if I can just get the player camera to pitch upward by an amount specified in the weapon datablock to simulate recoil I'd be a happy boy. ;)

EDIT: I inserted a pitch call in my client side scripting.... the camera now kicks upwards in an amount directly relative to the increased cone of fire... I'm a happy boy.

This is now ready to be added as a resource I think. I'll try to work something up in the next couple of days.
#4
08/10/2004 (1:06 pm)
Awesome, when do you think you can have the resource up on the site?
#5
08/11/2004 (2:12 pm)
It's really a matter of setting aside the time. Since there's intrest I'll get it together tonight. My first resource so no promises that I'll have it all 100% in the first shot. ;)
#6
08/11/2004 (5:52 pm)
Http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6235
#7
08/11/2004 (6:19 pm)
Good job, thanks alot, I'm going to try it out now ;)