place_meeting trouble

I'm making a basic space shooter arcade game and instead of using the built-in collision event I'm using place_meeting. Since this would have to be in the step event and the step event runs every frame I made a boolean variable named hit that will become true once an enemy hits the player's ship.

if (place_meeting(x,y, obj_enemy))
{
hit = true;
if (hit == true)
{
global.player_lives -=1;
hit = false;
}
}

The player is still dying in one hit. Can someone explain to me why, thank you.
 

OliverSB

Member
This code instantly sets hit to true then checks if it i true which it is so therefore every step this will decreases player lives by 1 and set hit back to false only for it to be set back to true next time you collide with the enemy.

The hit boolean check seems reduntant because its always true when checking.
 

OliverSB

Member
Are you trying to get the enemy to only do damage on the first step that it touches the enemy only then when it re-collides do more damage?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Let's take a closer look at the code.
Code:
hit = true;
if (hit == true)
You're setting the flag right before checking if it's set. Can it ever not be set when checking if it's set, then?
 
Top