Small instance creation/sprite bug

Elo

I'm making a zombie survival game, but for some reason all zombie types but one will hurt the player. In an animation end event I spawn an instance that acts as a kind of bullet that deals damage to the player within 10 pixels of a zombie. But for some reason the code in one of the instances doesn't work!! can someone please give me some guidance as to what might be going on here?

GML:
//broken zombie code
//create event
hp = random_range(100,150)
hurtav = true
path = 0
grid = mp_grid_create(0,0,room_width/8,room_height/8,8,8)
path = path_add()
foundplayer = false

//step event
if distance_to_object(player) < 5 {
    mp_grid_add_instances(path,owall,1)
    mp_grid_add_instances(path,owallfireover,1)
    mp_grid_path(grid,path,x,y,player.x,player.y,1)
    path_start(path,1,0,false)
    sprite_index = szombiemovemil
}
if distance_to_object(player) < 224 and !collision_line(x, y, player.x, player.y, owall, 1, 0){
    mp_grid_add_instances(path,owall,1)
    mp_grid_add_instances(path,owallfireover,1)
    mp_grid_path(grid,path,x,y,player.x,player.y,1)
    path_start(path,1,0,false)
    sprite_index = szombiemovemil
}

if hurtav and place_meeting(x,y,player) {
    sprite_index = szombieatkmil
}

if hp < 1 {
    path_delete(path)
    instance_create_layer(x,y,layer,ozombiedeadmil)
    instance_destroy()
}
if (!place_meeting(x,y,global.activechunk)) {
    instance_destroy()
}

if collision_line(x, y, player.x, player.y, owall, 1, 0) {
    sprite_index = szombiemil
}

//animation end event
if sprite_index = szombieatkmil {
    sprite_index = szombiemil
    instance_create_layer(x,y,layer,zombiehurttrace)
}
GML:
//working zombie code
//create event
hp = random_range(50,100)
hurtav = true
path = 0
grid = mp_grid_create(0,0,room_width/8,room_height/8,8,8)
path = path_add()
foundplayer = false

//step event
if distance_to_object(player) < 5 {
    mp_grid_add_instances(path,owall,1)
    mp_grid_add_instances(path,owallfireover,1)
    mp_grid_path(grid,path,x,y,player.x,player.y,1)
    path_start(path,1,0,false)
    sprite_index = szombiemovefire
}
if distance_to_object(player) < 224 and !collision_line(x, y, player.x, player.y, owall, 1, 0){
    mp_grid_add_instances(path,owall,1)
    mp_grid_add_instances(path,owallfireover,1)
    mp_grid_path(grid,path,x,y,player.x,player.y,1)
    path_start(path,1,0,false)
    sprite_index = szombiemovefire
}

if hurtav and place_meeting(x,y,player) {
    sprite_index = szombieatkfire
}

if hp < 1 {
    path_delete(path)
    instance_create_layer(x,y,layer,ozombiedeadfire)
    instance_destroy()
}
if (!place_meeting(x,y,global.activechunk)) {
    instance_destroy()
}

if collision_line(x, y, player.x, player.y, owall, 1, 0) {
    sprite_index = szombiefire
}

//animation end event
if sprite_index = szombieatkfire {
    sprite_index = szombiefire
    instance_create_layer(x,y,layer,zombiehurttrace)
}
I might take a really long time to reply too sorry guys

thanks
 

Nidoking

Member
What is actually happening? Do the sprites change, but the attack object doesn't spawn? Do the sprites not change? Have you checked the bounding boxes of the sprites to see whether there's a difference in bounding box or origin?
 
What is actually happening? Do the sprites change, but the attack object doesn't spawn? Do the sprites not change? Have you checked the bounding boxes of the sprites to see whether there's a difference in bounding box or origin?
yeah, the sprites do change and the animations themselves are playing and ending fine, the bounding boxes are fit to the sprites so that it covers the actual drawn sprite
 

sylvain_l

Member
silly question; where is the code that hurt the player ? Because the code you give us in the step event for what I understand only take care of the animations
 
silly question; where is the code that hurt the player ? Because the code you give us in the step event for what I understand only take care of the animations
nah thats a good question. heres the code for the players collision with the zombie bullet thing :

GML:
if sprite_index != splayerhurt {
    global.hp -= irandom_range(14,34)
    sprite_index = splayerhurt
    global.camhurtnotifier = true
    audio_play_sound(sohurt,0,0)
    instance_create_layer(x,y,"below",obloodsmall)
}
note: global.camhurtnotifier is a variable that just tells the camera to turn a red shade when you get attacked.
 
Top