Health not working, bullets pass through player[top down shooter]

P

peanutbuuter

Guest
i was making a top down shooter, and in a draw gui event i have this code:

global.hp = 10
global.max_hp = 10

health = global.hp/global.max_hp*100
draw_healthbar(608, 0, 640, 96, health, c_black, c_red, c_green, 3, true, false)

and in the collision with enemy bullet i had this:

global.hp = global.hp - 1;

if global.hp == 0{
instance_destroy()
}

but now the bullets just pass through the player

any help will be appreciated!
 

TheouAegis

Member
You are setting global.hp and global.max_hp in the Draw GUI event. That means your hp and max_hp will always be 10. Move it to the Create Event.

You didn't tell the bullets to destroy themselves when they collide with the player.

Also if the bullet's speed is too high, it can easily pass through the player. Make sure your bullet's speed is less than the player's width minus the player's max movement speed. Otherwise you need to calculate bullet collisions as a collision_line().
 
P

peanutbuuter

Guest
The bullets are fairly slow anyways, but I did what you said and it worked!
Thanks a bunch!
 
Top