How do I fix this bullet piercing code?

0 favourites
  • 5 posts
From the Asset Store
This pack contains 10 types of bullet effects, with different shapes and colors.
  • so I'm just hacking together a space shooter using the base elements for my first try at this, and I decided it would be cool if my bullets could pierce enemies when they do over the damage necessary, and not only that, but to also only do what damage was left from the last enemy, and I came up with this.

    unfortunately, this doesn't quite work as anticipated. The sniper shot does exactly double of the 3 health the basic enemies have, and instead of sniping two off before poofing off, I was able to kill as many as I could fit in a row, but if I use the basic weapon to hit one, it actually doesn't kill the second, it leaves 1hp on, and similarly if I take two off with the basic, it kills the first and leaves the second with TWO hitpoints, so it gets weaker as their health goes down...

    I've tried setting it to 'subtract x from y' but that just makes it snipe all the enemies no matter what, and I assume since the remaining health will be in terms of negative, I will want to add that negative value to the shot's damage to decrease it, but that's not happening.

    I can post the full game code if anyone requests it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm not able to see your image..

    But if I understand correctly it should be something like this:

    Your bullet should have an instance variable damage and your enemy an instance variable health

    bullet on collision with enemy

    • bullet.damage < enemy.health

    > set enemy.health : enemy.health-bullet.damage

    bullet destroy

    • else

    > set bullet.damage : bullet.damage-enemy.health

    enemy destroy

  • ahh dang... it keeps glitching out when I try to embed

    here's the full url

    https://drive.google.com/file/d/0B2pmnK ... sp=sharing

  • Well like I said..

    My above explanation should work..

  • hm. this seems to work right, but sniping an enemy that has previous damage will not take that damage into account, it will seem to hit the third in line, but no damage will have been done.

    have I set this up right?

    https://drive.google.com/file/d/0B2pmnK ... sp=sharing

    X| also I'm sorry if I'm sounding pestering, but all this programming logic is so alien to me it's hard to grasp it even after spending several years on various tutor sites like codeacademy.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)