B
brawny_b
Guest
Hey, I've picked up GameMaker: Studio 1.4 recently and was in the initial stages of making my first prototype while learning from a video series. After having programmed an individual enemy, I wanted to try and make having multiple of the same enemy object work. It took time and patience, but the individual enemy is now destroyed upon it reaching 0 health.
However, this has come with the newly found issue of the other enemy objects that have already been placed and the way lines of codes such as their vspeed/hspeed being reversed upon them leaving the boundaries of the room do not function for them. I have noticed this only in the enemies previously existing within the room rather than enemies that were created using instance_create() upon the first initial enemy being destroyed.
I am using code within the bullet and a script for an enemy to determine the hit registration and whether the enemy is left with one health or not. This is the code of the bullet checking to see what enemy was touching the bullet upon a collision (so it can be destroyed upon it reaching 0 health). Notably, if there are three of these enemies in the room and one respawns through the instance_create() line (line 14), then the problem doesn't take effect for some reason:
This is the code of the enemy. Most notably, lines 6-12 don't take effect upon an enemy being destroyed and not recreated, leading to the enemies to exit the boundaries of the room:
Line 16 of the above code is a simple script that fetches a separate ID to see what bullet was touching the enemy upon a collision. The bullet is meant to be destroyed which it does as intended, but when the bug takes effect, the bullet that destroyed the enemy will not be destroyed. This is the code of the script:
However, this has come with the newly found issue of the other enemy objects that have already been placed and the way lines of codes such as their vspeed/hspeed being reversed upon them leaving the boundaries of the room do not function for them. I have noticed this only in the enemies previously existing within the room rather than enemies that were created using instance_create() upon the first initial enemy being destroyed.
I am using code within the bullet and a script for an enemy to determine the hit registration and whether the enemy is left with one health or not. This is the code of the bullet checking to see what enemy was touching the bullet upon a collision (so it can be destroyed upon it reaching 0 health). Notably, if there are three of these enemies in the room and one respawns through the instance_create() line (line 14), then the problem doesn't take effect for some reason:
Code:
/* If the bullet exits the boundaries of the room, the bullet will be destroyed */
if y < 0 or y > room_height or x < 0 or x > room_width {
instance_destroy()
}
hitEnemy = instance_place(x,y,Ob_enemy)
if instance_exists(hitEnemy) {
with hitEnemy {
healthpoints -= 1
if healthpoints <= 0 {
instance_create(random(room_width), random(room_height), Ob_poof)
instance_destroy() // Enemy despawns upon reaching zero health
audio_play_sound(death, 15, false);
hitEnemy = 0
//}
}
}
Code:
/* Code influences the direction the enemy is facing */
image_angle = direction
/* Code influences what happens when the enemy touches the edge of a room*/
if y < 0 or y > room_height {
vspeed = vspeed * -1
}
if x < 0 or x > room_width {
hspeed = hspeed * -1
}
/* Code influences the damage of the enemy and how it should react */
Hit_Bullet()
Code:
hitBullet = instance_place(x,y,Ob_projectile)
if instance_exists(hitBullet) {
audio_play_sound(hurt, 10, false);
with hitBullet {
instance_destroy() //Bullet is checked for and then destroyed upon contact with an enemy
}
}
Attachments
-
80.5 KB Views: 28
-
52.1 KB Views: 28
-
39 KB Views: 28
Last edited by a moderator: