L
lauralie
Guest
Hi! I'm adding player health hearts in my game. When the players health goes down the hearts go down. Right now I have it so that the number of hearts correctly correspond to the number of the players health. If I manually change the players health variable it correctly displays in the game. Now I'm trying to make it so that when they player is touched by an enemy they lose a heart/1 health.
But when they get touched they loose all their health and die immediately.
This is my code for when the player touches an enemy. The variable for the global health is set to 3. Not sure what's making them die still upon being touched?
But when they get touched they loose all their health and die immediately.
This is my code for when the player touches an enemy. The variable for the global health is set to 3. Not sure what's making them die still upon being touched?
GML:
if place_meeting(x,y,oEnemy)
{
global.playerHealth--;
if (global.playerHealth <= 0)
{
with (oGun) instance_destroy();
instance_change(oPDead,true);
direction = point_direction(other.x,other.y,x,y);
hsp = lengthdir_x(6,direction);
vsp = lengthdir_y(4,direction)-2;
if (sign(hsp) != 0) image_xscale = sign(hsp);
}
}