• 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!

3D Question with doors

Mistafar

Member
Hello
I have tried many codes but nothing comes out.
The idea is to open the door (and change the sprite of course) after pressing the left mouse button.
Bez tytułu.png


i've got only this in obj door


Przechwytywanie.PNG
 

FrostyCat

Redemption Seeker
Not even something basic like this?

Door Create:
GML:
closed = true;
Door Step:
GML:
if (keyboard_check_pressed(vk_enter) && distance_to_object(obj_player) < 16) {
    closed = !closed;
}
Door Draw:
GML:
if (closed) {
    /* Put the door drawing code from your original Draw event here */
}
You can't copy, watch, or hail-mary your way to success in this line of work. Learn some elementary GML first, and if at all possible, start on an actively maintained version of the software instead of a legacy version that has been past sunset for several years.
 

Joe Ellis

Member
You probably want to detect whether the player is in front of the door and facing it, and check if the left mouse button is pressed.
Something like this maybe in the player's step event:

GML:
if mouse_check_button_pressed(mb_left)
{

//Loop through all instances of obj_door
with obj_door
{
    //Check distance is within a certain range
    if point_distance(x, y, other.x, other.y) < 64
    //Check the direction from the player to the door
    //is facing mostly the same way as the player's yaw(or facing angle\direction of the view)
    && abs(angle_difference(point_direction(other.x, other.y, x, y), other.yaw)) < 90
    {
    open = !open;
    //This will probably be the only door the player is near to, so you can break the loop here
    break;
    }
}
}
Then just draw a different sprite depending whether it's open or closed.
 
Last edited:
Top