Closing doors without getting stuck in them

Discussion in 'Programming' started by General Woodchuck, Jun 3, 2018.

  1. General Woodchuck

    General Woodchuck Member

    Joined:
    Jan 25, 2018
    Posts:
    19
    Making a top down RPG. I've got it set up right now where if you hold the action button, he will slowly peak through the door and open it more and more until it's fully open.

    This works fine, however if I go to close it while I'm standing right in the middle of the door, my character gets stuck inside it.

    The code for my character is shown below. This is just an example for when he is using a door that is to his left, and opens outward.

    The way the door works is if it's "open" (or image_index = 5 <-- which is the frame where the door looks open) then solid = false (can walk through it), else: solid = true (can't walk through it). So if my character closes the door on himself he gets stuck in it and can't move until he open's it again.

    Ideally I'd like to do this:
    If my character is touching the center of the door object, bump him over so that the left side of the character object is touching the right side of the door. I still haven't completely grasped the bbox_left, bbox_right thing and I've also experimented with the "sprite_width" but can't figure out a good way to use that either.

    I hope I asked that in a way that makes sense.... Any help is very much appreciated!



    Code:
    {
    if (keyboard_check_pressed(vk_alt)){show_message(string(obj_doorP_w.bbox_right))}
    }
    //wDoor to the left, open outward
    if ((distance_to_object(obj_doorP_w)<=6)&&(obj_doorP_w.x<=x)&&(keyboard_check(keyAction))&&!(distance_to_object(obj_doorP_w)>6)&&(!keyboard_check(keyRun)))
        { 
            {if (obj_doorP_w.doorOpen==true&&place_meeting(x,y,obj_doorP_w)&&facing=="w"){x = x + 10}};       
            {if (sign(obj_doorP_w.bbox_bottom)>1&&place_free(x-speed,y)){x += sign(obj_doorP_w.x)} {y += sign(obj_doorP_w.bbox_bottom - bbox_bottom)}}; //if not close to knob, move closer
            if (place_meeting(x-1,y,obj_doorP_w)) //doorW to the west, open OUTWARD(to the west)
                {speed=0}
                {openingDoor = true}
                {image_speed = 0}
                {sprite_index=openDoorW}
                {image_index = obj_doorP_w.openness}
                {if (keyboard_check(keyLeft)){obj_doorP_w.openness = obj_doorP_w.openness + .5}}
                {if (keyboard_check(keyRight)){obj_doorP_w.openness = obj_doorP_w.openness - .5}}       
        }
    else
        {
            if (keyboard_check_released(keyAction) or (keyboard_check_pressed(keyRun)))
            {
                openingDoor = false
                image_speed = def_imgSpeed
                if (sprite_index=openDoorW or sprite_index=pullDoorW){sprite_index=idleW}
                if (sprite_index=openDoorE or sprite_index=pullDoorE){sprite_index=idleE}
                if (sprite_index=openDoorN or sprite_index=pullDoorN){sprite_index=idleN}
                if (sprite_index=openDoorS or sprite_index=pullDoorS){sprite_index=idleS}
            } 
     
  2. Becon

    Becon Member

    Joined:
    Jul 13, 2016
    Posts:
    109
    If this is what you mean, GM-Door.gif I would make the block in front of the door be part of the trigger. Shown in blue.
    If player is touching the blue floor and door touches him, player.x += 1. This will move him to the right if he's both standing on the blue and touching the door. Technically you don't need the blue to make it work but by using it you can set variables that can make other things happen like making the door pass through him if you want. You can just turn off the activation of the blue floor.

    If player touches blue floor AND door is solid, then move him to the right. ETC.
    Let me know if this helps. Or if you like that sick animation. =o)~
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice