GameMaker Bullets affecting multiple enemies

O

Oniric

Guest
Hi guys, so I'm currently working on a top/down zombie shooter and I've stumbled upon a problem. I have a shotgun which shoots 3 bullets, the problem is that let's say two of those bullets collide with 2 enemies it only affects one enemy, so basically until I kill the first enemy that was affected I cant kill the second one. Any idea why this might be happening?

if global.cur_weapon == 2
{
new_bullet = instance_create_depth(x,y,10,global.weapon_array[global.cur_weapon,2])
new_bullet2 = instance_create_depth(x,y,10,global.weapon_array[global.cur_weapon,2])
new_bullet2.direction += 20
new_bullet3 = instance_create_depth(x,y,10,global.weapon_array[global.cur_weapon,2])
new_bullet3.direction -= 20
}
This is the code, global.cur_weapon == 2 (This is the shotgun)
 
R

Rz12

Guest
i think that problem came from speed of bullet, you should try using collision_line
 
O

Oniric

Guest
This is certainly not the code with the problem, can you show your bullet code?
I suspect you do something like this based on what is happening.
Code:
if (place_meeting(x, y, obj_enemy))
{
   obj_enemy.hp -= 1;
}
You may need to read this
https://forum.yoyogames.com/index.php?threads/whats-the-difference-objects-and-instances.29005/
if place_meeting(x,y,global.weapon_array[global.cur_weapon,2]) // If ZOMBIE in contact with projectile.
{
zombie_health -= 50; // Removes 50 health points
with(global.weapon_array[global.cur_weapon,2]) // Destroys the Projectile
{
instance_destroy();
}
}
This is the code I have within the zombie enemy, so what approach should I take here what exactly is it that I'm doing wrong?
 

kburkhart84

Firehammer Games
It looks like you have that code on the zombie...that means that each zombie would have its own health...that's good. My issue is that with the separate bullets, you are destroying all of them at once. That global array you are using to determine which bullet to create I believe is the name of the object, and you are creating instances of that object. But, when you check for collisions later, you can't just check the same way using the object name, because it will access all the bullets at once. And in this case, the with statement is simply executing instance_destroy() for all of those bullets at the same time. You need to figure out a way to access a single instance of the bullet and destroy that. The most common way is to use collision events, as those happen on each individual instance instead of on the object name itself. Above someone linked a part of the manual about the differences between objects and instances...I'd recommend you take a look at that.
 
Top