• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Collision with opening door

S

stepup2000

Guest
So im making a door right now and everything is working perfectly(top down game btw), the only thing that im not happy about is the fact that when i open my door, i get stuck in it for like half a second because the collision box of the door "hits" me a second, resulting in me getting stuck for a brief moment, i dont know how to fix this since every time i have an collision event with something game maker won't let me trough it, even without putting code in the collision event, i was thinking about turning the collision event off when the door is moving but this didnt work (because there is still a collision event) anyone knows how to fix this?
 

samspade

Member
Are solids turned on? What does the code look like.

One fix would be to separate the visible door from the impassable object. In other words. Have a door object which looks and acts like the door, but doesn't care about collisions with the player - e.g. could be walked right through - but have it control another invisible object that is impassable. Have it delete the object when open and make it when closed, or move it, or whatever works.
 
One way several games solve this problem is by making the door always swing away from the player. Then you just need to make sure no NPC will ever stand close to a door or that the door doesnt collision check NPCs.
 
N

NeonBits

Guest
Forget the collision event and work with coordinates; define an x/y zone and make it accessible or not accessible depending on a variable; make sure the variable will change only when you are outside of the zone; if the zone is not open, make it solid or cancel your movement in that direction.
 
S

stepup2000

Guest
Are solids turned on? What does the code look like.

One fix would be to separate the visible door from the impassable object. In other words. Have a door object which looks and acts like the door, but doesn't care about collisions with the player - e.g. could be walked right through - but have it control another invisible object that is impassable. Have it delete the object when open and make it when closed, or move it, or whatever works.
No the door is not solid, but as soon as I add a collision even with something I can’t go trough it with my character (doesn’t even matter if the collision event is with the character, I just can’t go trough it) I’m gonna give your idea a try, the only problem then is that when you have a lot of door it’s gonna be a lot of extra objects (do make a invisible barrier for every door.
 
S

stepup2000

Guest
One way several games solve this problem is by making the door always swing away from the player. Then you just need to make sure no NPC will ever stand close to a door or that the door doesnt collision check NPCs.
The problem with that is that as soon as the door swings away from the player the door goes in the house, this results in not seeing the door anymore and you will only see a huge ugly gap in the wall where the door used to be (if you are still standing outside
 
S

stepup2000

Guest
Forget the collision event and work with coordinates; define an x/y zone and make it accessible or not accessible depending on a variable; make sure the variable will change only when you are outside of the zone; if the zone is not open, make it solid or cancel your movement in that direction.
I’m not sure if I understand exactly what you mean, but I tried using the distance to object function, the problem with this is that he calculates the point from the center point you gave the door, so let’s say I have a range of 10 pixels. this will be fine for the horizontal(if the door is 10 pixels long), but this will also mean he calculates 10 pixels vertical resulting in a huge gap between the player and door (let’s say the width of the doors is 2 pixels) resulting in a 8 pixel gap
 

pixeltroid

Member
OP, I had the same problem with doors. My player would get stuck for a moment in the door as it opens. Then when I tried to fix it, player would just be able to walk through the door. Or...would be unable to unlock the door! Really frustrating.

So I used the invisible barrier method instead. i.e, the invisible barrier is overlaid on the graphical door which is seen on screen. But the graphical door would just be an empty non-solid object with a sprite attached to it . The invisible barrier would be a solid object that is interactive with my player and self destructs upon touching it. So once the invisible barrier is destroyed the door objects sprite gets changed to a sprite of the door opening....thus allowing player to move past it.

It's quite silly but it works and thats whats most important. I'm sure there's a better method but I didnt want to waste any more time trying to fix my door system.
 
Last edited:
N

NeonBits

Guest
Maybe you should describe the gameplay; in some games, the door just open as you get near; in other games, they will only open if you trigger them with something else. You could use a collision rectangle; once you enter its zone, if the variable is false, it becomes true, then the door open; the variable will reset to false only once you exit to the next collision rectangle, if one was made, or when you exit the first one.
 
S

stepup2000

Guest
OP, I had the same problem with doors. My player would get stuck for a moment in the door as it opens. Then when I tried to fix it, player would just be able to walk through the door. Or...would be unable to unlock the door! Really frustrating.

So I used the invisible barrier method instead. i.e, the invisible barrier is overlaid on the graphical door which is seen on screen. But the graphical door would just be an empty non-solid object with a sprite attached to it . The invisible barrier would be a solid object that is interactive with my player and self destructs upon touching it. So once the invisible barrier is destroyed the door objects sprite gets changed to a sprite of the door opening....thus allowing player to move past it.

It's quite silly but it works and thats whats most important. I'm sure there's a better method but I didnt want to waste any more time trying to fix my door system.
yeah i thought about that aswell, but the problem is that i have around 50 doors in one room. so if i have to use 2 objects for every door it gets quite heavy.
 
S

stepup2000

Guest
some doors have to be unlocked with
Maybe you should describe the gameplay; in some games, the door just open as you get near; in other games, they will only open if you trigger them with something else. You could use a collision rectangle; once you enter its zone, if the variable is false, it becomes true, then the door open; the variable will reset to false only once you exit to the next collision rectangle, if one was made, or when you exit the first one.
an key and some door you can always open. right now i use this for my door:

if instance_exists(obj_man) {
if distance_to_object(obj_man) < 5 {
//do the stuff i wanna do
}
}

this works good enough, so the only thing left is the collision, i cant use the code i already used because of how the distance is calculated (i explained this in my first comment)
 
N

NeonBits

Guest
You cannot be everywhere at the same time; only one door will be triggered at once; you could define each zone with "collision_rectangle", time consuming, or, like pixeltroid has suggested, create one invisible object and add its instances to your doors to emulate an obstacle; make the sprite of your door larger (not its design) so you can set its collision mask in the empty space in front of it; like this, you can check for a collision with the door's id without using "distance to object" and interract with its variables to open the door; if it's unlocked, the invisible object doesn't need to be destroyed, simply change its "solid" variable to "false" and, once you've passed the door or exit the collision mask, reset it to "true"; the player won't notice that all doors aren't an obstacle anymore for being only in one place at a time.

I'm certain there are better ways for your puzzle. For being a beginner, please take my solution as a suggestion only.
 
Top