Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Help!
#1

Ammo Logic

Archive: 13 posts


Hey guys,

I'm having a few issues with regards to ammo for my weapons. Currently I just have a counter set to x amount of bullets for each gun, which when full activates the reload animation. This was originally fine as I had a separate counter for number of magazines, which increased whenever the gun was reloaded, and when full, the gun wouldn't fire any more as it would be out of ammo. However I've just introduced logic which allows the player to reload at any point. I can't think of a way to effectively keep track of how many bullets the player has left!

For example if the player has 20 bullets (with 2 magazines of 10 bullets each). If the player fires 6 bullets and then reloads, the game needs to add 4 bullets to the current magazine and subtract it from the total bullets (meaning the second magazine would only have 6 bullets left in it if the first magazine was then emptied). Any ideas?
2012-07-24 13:29:00

Author:
Mopkins
Posts: 123


That sounds really complicated, you would pretty much have to track each bullet to do what youre talking about. The logic would be mind boggling but... you could pretty much do something similar to this. This is my secret logic from my pirate level where I hid 8 treasure boxes around the level and it rewards you at the end based on how many you found.

http://i0.lbp.me/img/ft/b7014e9fcbdb0b60b9b776a46ae52e66d4f20741.jpg

hitting any of the counters at the bottom fill it and feed into a series of other counters each with +1 than the last. The XOR gates are fed into one another and it only activates the furthest one in the chain. Whatever XOR is turned on activates the microchip at the top, but again this is what it would look like tracking 8 bullets, on magazine of 30 or so would be crazy

A more friendly solution would be to do this

http://i2.lbp.me/img/ft/2a2098c2b89f050384d156de6df39e1ba486142b.jpg

Hitting square starts the reload action cycling your mags, the counter on the left is an inverted of 30 counting if you wish to display total bullets remaining while the 3 at the bottom are inverted of 10. Hitting X takes one bullet away from your current mag. It would just cycle through each mag, if one is full great if not, then you can use what's in it or cycle again. But ultimately I would just an inverted counter that launches the reload animation when empty and has limited reloads. letting the player do it seems way too intensive
2012-07-24 18:39:00

Author:
Unknown User


Yeah I couldn't think of a way to do it without blowing my mind with the logic. Especially as I want to introduce an upgrade system! Was just wondering if there was something I had overlooked. Might have a play around with it and see what I can come up with. I had a thought earlier though, would it be easier to use analogue signals and addition to achieve this? I'm fairly new to analogue logic so I'm not sure how to go about using it effectively.2012-07-24 19:05:00

Author:
Mopkins
Posts: 123


Store the current count of bullets for the gun in a feedback loop; each shot subtracts 1% from this to the point that the looping value is 0. You'd fully reset the loop by feeding it a high value (say 31% for an AK, or 51% for a SMG, whatever).

Say you'd want a manual reload action, you'd take the max value for that gun (AK: 31) and subtract the current loop value from it (for example 10) using a signal combiner; the resulting value (in this case 21) you add to the gun loop AND you subtract it from a separate feedback loop that keeps track of the total number of bullets.

When the total ammo feedback loop reaches 0, it is all over. You can then add features like running past an ammo cache that will refill your total ammo loop.
2012-07-24 19:08:00

Author:
Antikris
Posts: 1340


I think I follow that, I'll give it a go and see what I can come up with. Thanks! 2012-07-24 19:27:00

Author:
Mopkins
Posts: 123


Reply is worthless without pics.


The ammo

http://i.imgur.com/3H1bX.png


The gun

http://i.imgur.com/uWyXI.png

These self-resetting things are one-shot counters. The tag sensor is set to signal strength.

Not that I have not put in any logic to detect that the gun is empty; you can use a positional sequencer for that, with a battery spanned across the canvas, wired to a NOT gate. The same logic can be used to detect all ammo is depleted.

You probably want to use some analog to digit logic to get these signals displayed as numbers; that is a whole new ballgame, though. For checking and debugging any signal probe will do.

You may run into the problem that you'd want to stock higher than 100 bullets ammo; in that case, say we stock 400 bullets. That is still 100%; however, guns should then have a max value of 1/4 of their current battery signals: so, 21% becomes 5.25% and 31% becomes 7.75%. You'd also not subtract 1% per bullet, but 0.25%.

In order to get those fractional values, instead of using batteries, use timers that are frozen by a 0% battery; for instance, a 1% value can be reached with a timer set to 100s max and 1s current. Likewise, 7.75% is a timer set to 10000s max and 775s current.

And in case you were wondering, the above logic was tested and it works.
2012-07-24 19:58:00

Author:
Antikris
Posts: 1340


I have a 100% functioning realistic ammo system for my shooter Zombie Epidemic
(http://lbp.me/v/czqhd7) which does what you're asking for (ammo math) but displays all bullets individually for both clip and reserve ammo instead of having a magazine display. It's very flexible and works well with my Boxhead-style upgrade system.

I think you might be kidding yourself by wanting to display magazines left instead of all reserve bullets left, unless you're going for a realistic tactical shooter kind of level.

I don't have any pics right now of my logic, but there's a lot of it, and it's a little messy, although I could show it to you or post some pics here and explain it. It should help tremendously with what you're making.
2012-07-25 03:28:00

Author:
BIGGamerer
Posts: 182


One more note to my illustrated solution: it becomes pretty tricky when working with fractions of percentages; the easiest way would be to just divide by 10, restock ammo by 40% (400 bullets) and subtract 0.1% for each bullet. When monitoring with a signal probe, however, you'll soon find a minute fractional signal offset. You'll end up not with 0% on an empty gun, but 0.0001%, which will mess up your logic if you are using a sequencer to establish true 0.

You can compensate by subtracting 0.0005% or something before the signal goes into the sequencer, but be sure to stream it through a splitter first and use the positive output or else anything below 0 (-0.0004) will turn up as a not-0 value again for the sequencer.

Also, switching between guns, from 21 bullets to 31 is not a problem, but switching from a higher mag count to a lower one will not override the gun loop value. For that to happen, stream the loop through a 3-gate XOR gate before the OR gate and wire the 1-shot counter for resetting the gun to the two remaining XOR input. When the reset fires it essentially blocks the throughput of the XOR gate, interrupting the loop, setting it to 0, right before it will inject its new mag value into it.
2012-07-25 09:32:00

Author:
Antikris
Posts: 1340


For that to happen, stream the loop through a 3-gate XOR gate before the OR gate and wire the 1-shot counter for resetting the gun to the two remaining XOR input. When the reset fires it essentially blocks the throughput of the XOR gate, interrupting the loop, setting it to 0, right before it will inject its new mag value into it.

ideally you'd want to send it back to total ammo loop rather than dumping it
2012-07-25 10:14:00

Author:
evret
Posts: 612


One more note to my illustrated solution: it becomes pretty tricky when working with fractions of percentages; the easiest way would be to just divide by 10, restock ammo by 40% (400 bullets) and subtract 0.1% for each bullet. When monitoring with a signal probe, however, you'll soon find a minute fractional signal offset. You'll end up not with 0% on an empty gun, but 0.0001%, which will mess up your logic if you are using a sequencer to establish true 0.

You can compensate by subtracting 0.0005% or something before the signal goes into the sequencer, but be sure to stream it through a splitter first and use the positive output or else anything below 0 (-0.0004) will turn up as a not-0 value again for the sequencer.

Also, switching between guns, from 21 bullets to 31 is not a problem, but switching from a higher mag count to a lower one will not override the gun loop value. For that to happen, stream the loop through a 3-gate XOR gate before the OR gate and wire the 1-shot counter for resetting the gun to the two remaining XOR input. When the reset fires it essentially blocks the throughput of the XOR gate, interrupting the loop, setting it to 0, right before it will inject its new mag value into it.

Don't use timers. Use a mover and speed sensor to calculate precise signals. That's what I used to get values of 1-1000 for use in my shooter Zombie Epidemic with absolutely no errors like the ones you're describing in this post. (The pic shows division by 2, but division by anything seems fine. Capture the signal you want into a mini feedback loop, which is a circuit node wired to itself with the signal, and use that for the subtraction and addition of bullet ammo. I don't have much time to explain this right now, sorry. Hopefully it's straightforward enough though.)

http://i4.lbp.me/img/ft/8248930c45d39bd497c7625f1fc0355a35e2b51f.jpg
2012-07-25 12:13:00

Author:
BIGGamerer
Posts: 182


ideally you'd want to send it back to total ammo loop rather than dumping it

That is what the 'reload' action is for. Its practical application needs work but imagine the 'reset' being triggered when picking up a new, already loaded gun from somewhere. It'd also have its use (together with the ammo reset) when dying and respawning.


Don't use timers. Use a mover and speed sensor to calculate precise signals. That's what I used to get values of 1-1000 for use in my shooter Zombie Epidemic with absolutely no errors like the ones you're describing in this post. (The pic shows division by 2, but division by anything seems fine. Capture the signal you want into a mini feedback loop, which is a circuit node wired to itself with the signal, and use that for the subtraction and addition of bullet ammo.

That makes sense, thanks. I have seen people propose this before, it may have even been you. An already captured feedback node is harder to change lateron, though.
2012-07-25 12:51:00

Author:
Antikris
Posts: 1340


That is what the 'reload' action is for. Its practical application needs work but imagine the 'reset' being triggered when picking up a new, already loaded gun from somewhere. It'd also have its use (together with the ammo reset) when dying and respawning.



That makes sense, thanks. I have seen people propose this before, it may have even been you. An already captured feedback node is harder to change lateron, though.

That's where the feedback override chip in pivott's health meter toolkit comes in handy for replacing values in a feedback loop.
2012-07-25 15:30:00

Author:
BIGGamerer
Posts: 182


Hah, I never realized the speed sensor was so accurate, awesome.

Thanks are due throughout this thread I think
2012-07-27 01:33:00

Author:
SSTAGG1
Posts: 1136


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.