Fire Multiple Weapons Simultaneously
by Charlie Sibbach · in Torque Game Engine · 01/01/2009 (12:56 pm) · 1 replies
OK, this was a request for input, but since I found the answer and it may help someone else, I'm going to post this little tidbit.
I have a bunch of weapons mounted on a vehicle (2 actually, but mores 'a comin'), and I could NOT get them to fire simultaneously. I had based my code on the venerable Helicopter Resource (http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9263), but turns out there was no way that it was working correctly as posted in the archive (I don't think I ever tested it as a complete thing, I ripped out some physics code and the chaingun as a sample weapon). On my ship, with the primary trigger I could get the weapon in slot 0 to fire, and with the secondary trigger I could get the weapon in slot 1 to fire, but nothing I did in script seemed to matter- I had a function that called
Which was called when trigger 0 was pressed, but only the weapon in slot 0 would fire. Huh.
So I did some digging into the engine. Turns out that my setImageTriggers() from script were being overridden at the engine level in Vehicle::updateMove(), which had hard-coded the image triggers for slot 0 and 1 to triggers 0 and 1. So in what turned out to be one of the easiest bugfixes on record, I removed these lines at the top of vehicle.cc's Vehicle::updateMove():
With this change, the image triggers are controlled only from script, and my weapons now fire beauteously in parallel.
This same code appears in Player.cc as well, so if you're mounting more than two weapons (or need twin-firing weapons) you'll want to do away with it as well.
PS: On further review of the Helicopter code, there is a bunch of stuff in there to alternate the triggers of weapons 0 and 1 from script via schedule(). I never understood why before- I think now that it was an elaborate method to fire both the guns from a single trigger. I can't confirm, but this fix makes it totally unnecessary.
I have a bunch of weapons mounted on a vehicle (2 actually, but mores 'a comin'), and I could NOT get them to fire simultaneously. I had based my code on the venerable Helicopter Resource (http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9263), but turns out there was no way that it was working correctly as posted in the archive (I don't think I ever tested it as a complete thing, I ripped out some physics code and the chaingun as a sample weapon). On my ship, with the primary trigger I could get the weapon in slot 0 to fire, and with the secondary trigger I could get the weapon in slot 1 to fire, but nothing I did in script seemed to matter- I had a function that called
MyVehicle.setImageTrigger(0, true); MyVehicle.setImageTrigger(1, true);
Which was called when trigger 0 was pressed, but only the weapon in slot 0 would fire. Huh.
So I did some digging into the engine. Turns out that my setImageTriggers() from script were being overridden at the engine level in Vehicle::updateMove(), which had hard-coded the image triggers for slot 0 and 1 to triggers 0 and 1. So in what turned out to be one of the easiest bugfixes on record, I removed these lines at the top of vehicle.cc's Vehicle::updateMove():
// Image Triggers
// FIXME: This may need to be updated to truly get all the weapons to fire.
if (mDamageState == Enabled) {
setImageTriggerState(0,move->trigger[0]);
setImageTriggerState(1,move->trigger[1]);
}With this change, the image triggers are controlled only from script, and my weapons now fire beauteously in parallel.
This same code appears in Player.cc as well, so if you're mounting more than two weapons (or need twin-firing weapons) you'll want to do away with it as well.
PS: On further review of the Helicopter code, there is a bunch of stuff in there to alternate the triggers of weapons 0 and 1 from script via schedule(). I never understood why before- I think now that it was an elaborate method to fire both the guns from a single trigger. I can't confirm, but this fix makes it totally unnecessary.
Torque 3D Owner Hans Cremers
Thanks !