How do I Create automatic doors?

0 favourites
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game

    I am looking for some advice, please, about the doors in my game.

    It is a sidescroller. The idea is simple: Player walks up to a door, door opens. once player walks away from the door, door closes again.

    i do this with player.x and door.x but here is the thing: it should work from both sides, so i figure i have to use lerp but i have no idea how that works. also, the door must always open fuly and close fully, preferably until it hits a solid tile.

    so the code should be something like

    if door.x is less than player.x+80 then use 8 direction up until you hit a solid tile. then switch on instance variable to "open" and stay there. if player is away more than 80 then close until you hit a solid tile and then switch to instance variable "closed"

    i can do most of that but i have a problem with the range. how exactly do i tell the door that it should only move if player is closer than 80 in both directions, left and right? and only that particular door?

    You can use distance(player.X, player.Y, door.X, door.Y)

    Okay, and how do i set it up? do i put that in the door sprite? compare X and then this or how does that work?

    Simply compare two values.

    if distance(player.X, player.Y, door.X, door.Y) > 80 - close doors

    else open doors

    okay but HOW EXACTLY do i set that up?Sorry but I have NO clue what that means

    compare two values is a system event.

    You will compare the distance of the two objects as shinkan described.

    This will have an action to either keep the doors open, or close them depending on how you set it up. You will have to have a sprite for this, and probably disable collision on the door when open.

    you then need an else statement to do exactly the opposite.

    Very rough example

    If you don't have r182 here's the screenshot:


    okay thanks,

    i set that up with else and everything but it still does not work

    i put a soundfile in just to test before i ut the open door code in and, well, the soundfile plays over and over until i move close to the door on one side, and that's it.

    i have multiple doors, is that the problem?

    edit: i put in the movement and now all doors in the map just move down and are gone - no matter how close i am

    personally I find it easier having an open animation frame and a closed animation frame. All you do is change the frame. No movement or changing angles.

    Just remember to turn off/on the collision.

    This way keeps sprites where they need to be pretty reliably.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads

    still doesnt change the fact that i can't get it to work to actually do something when the player is closer than 80 on both X sides. i can get it to work on one X side but not on both. Technically i could try to fake it by mirroring it depending on where the player is and then check the door if it is mirrored or not and compare that to the player distance on X BUT that is an overly complicated way and does not really do what i need since the door would then only move if the player is within that radius.

    so any help on that would be appreciated, but thanks for the comments so far

    "distance(player.X, player.Y, door.X, door.Y)" expression works no matter on which side you are.

    It would be easier if you post your capx file.

    should be as easy as checking

    abs(player.x-door.x) <80

    You could use a for each door if you have difficulties with multiple instances

    I'm not sure what kind of events you are using to make the doors move, but making it a triggered event or trigger once while true would be best..

    i copied the expressions from shinkan into my game and it does not work. i can't post the capx due to NDA but as said, i did EXACTLY what i was supposed to do and it did not work.

    i'll try the abs thingy now and see where that takes me though

    edit: well abs opened the door when i came in from the right, but not from the left so its pretty much exactly the same as simply comparing x

    it shouldn't be the same..

    So if you could make a screenshot of your events it might become clearer where the flaw is..

    This should be pretty simple, you might want to recreate your issue in a simple capx, so we could fix that..

    but all i do is copy YOUR code into my game. the entire door file has NO OTHER CODE WHATSOEVER!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)