Gleb
Member
Making a game where the player can hide behind things. There's two layers, Active1 and Active2.
The objects you can hide behind are on Active1, as well as the player. When the player hides, they'll be moved to Active2, behind the hideable objects.
I originally intended for this to work as such, the player presses E when colliding with a hideable object, then moves to Active2. When the player walks out from behind the object (stops colliding) they are automatically moved to Active1 again.
I couldn't make this work because i was using !place_meeting in the step event, which meant i couldn't re-use the hideable object instance. (The player would never be hidden unless colliding with every instance which is impossible)
If somebody here knows how i could achieve the above that would be amazing.
Perhaps my understanding of depth is off. The below code is flawed. Now hiding works like a toggle. The player had to press E again to come out of hiding. The only issue is, with the current code once they come out of hiding they can't go back in.
I'm not sure why. The cooldown function makes sure the input is only read once.
In the key up (E) event of the object the player hides behind:
Any thoughts help, thanks in advance.
The objects you can hide behind are on Active1, as well as the player. When the player hides, they'll be moved to Active2, behind the hideable objects.
I originally intended for this to work as such, the player presses E when colliding with a hideable object, then moves to Active2. When the player walks out from behind the object (stops colliding) they are automatically moved to Active1 again.
I couldn't make this work because i was using !place_meeting in the step event, which meant i couldn't re-use the hideable object instance. (The player would never be hidden unless colliding with every instance which is impossible)
If somebody here knows how i could achieve the above that would be amazing.
Perhaps my understanding of depth is off. The below code is flawed. Now hiding works like a toggle. The player had to press E again to come out of hiding. The only issue is, with the current code once they come out of hiding they can't go back in.
I'm not sure why. The cooldown function makes sure the input is only read once.
In the key up (E) event of the object the player hides behind:
GML:
if cooldown <= 0 && place_meeting(x,y,P_Player){
cooldown = 10;
if P_Player.layer == layer_get_id("Active1") {
P_Player.layer = layer_get_id("Active2") ;
P_Player.hidden = true;
P_Player.depth = self.depth + 1;
}else if P_Player.layer == layer_get_id("Active2") {
P_Player.layer = layer_get_id("Active1") ;
P_Player.hidden = false;
P_Player.depth = self.depth - 1;
}
}