How do I fix this bullet piercing code?

Get help using Construct 2

Post » Fri Jul 10, 2015 1:49 pm

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.
Image
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.
B
12
S
5
Posts: 19
Reputation: 1,025

Post » Fri Jul 10, 2015 2:12 pm

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 10, 2015 2:51 pm

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
B
12
S
5
Posts: 19
Reputation: 1,025

Post » Fri Jul 10, 2015 3:43 pm

Well like I said..
My above explanation should work..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jul 10, 2015 7:40 pm

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.
B
12
S
5
Posts: 19
Reputation: 1,025


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests