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

[SOLVED] Need Help With Preventing the Player From Moving When Transported to New Room

S

sjschindler

Guest
Hello again. I never did thank the two lovely people who helped with the last issue I had, so thank you to them.

Right now, I have a game that has portals that connect between two rooms. I also have a fade transition that requires the player to always collide with the object. That is not the issue here, and I have already found a workaround for that. My issue is that when I am transported to the next room, I want to have my movement stopped for a few seconds to allow the fade to finish before a player can move again. I do understand you can just not press the right arrow key and everything will be fine, but sadly during playtesting, I found that everyone(literally everyone) kept holding down the right arrow key. So in order to combat this habit, I wanted to make it so the player would stop moving, even if the player was holding the right arrow key for a few seconds.
Can anyone understand what I'm saying and help me if so? I've been combating this problem on my own for a few days and I would appreciate any help. Thank you!

Movement Code:
///Movement for Nyx
//Get Player Input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);

//React to inputs

move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (move = 0)
{
image_index = 1
}

if(keyboard_check_pressed(vk_right)) facing = 1;
if(keyboard_check_pressed(vk_left)) facing = -1;

if keyboard_check(vk_shift)
{
hsp = move * (movespeed * 3);


}
 
W

whale_cancer

Guest
Simply create a variable - call it, say, can_move - and set it to false when the player enters the new room. At the same time, set an alarm that, when it triggers, sets can_move to true.

Put if (can_move == true) as a condition on all your move code.

Make sense?
 

Mr Magnus

Viking King
Another possible solution would depend a bit on how your fade mechanism works; but instead of having a seperate can_move variable you can simply check for the existence of the fading.

If your fading using an object, test if the object still exists before allowing movement. If your object is a variable in some other object read the value of said instance.variable.
 

NightFrost

Member
Put if (can_move == true) as a condition on all your move code.
It might be preferable to avoid putting large sections of code inside conditionals, as it makes debugging slightly more complex. Because the character should be completely unresponsive during a fade, instead put as the first line in step event:
Code:
if(can_move == false) exit;
 
S

sjschindler

Guest
Thank you all for your replies.
I set a variable can_move to equal true in the create event (can_move = true). Then in the step event, I set at the very beginning: if (can_move == false) exit;.
Then, in another code execution in the player object under the step event, set a check to see if the room I was currently in was the next room.
//Check to see if room is rm_ghost
if (room = rm_ghost1)
{
can_move = false;
alarm[0] = 120;
}

Game is set to be 60 fps, meaning that the alarm should go off for two seconds.
For alarm 0, I set can_move to equal true (can_move = true).
However, the problem I have now is that my character stays stuck unless I hold down a movement key. The issue with this is that for every two seconds that pass, if it hits exactly 2 seconds and I'm holding a direction, the player would only move a few pixels in the direction(5 pixels per frame is what I set the movement speed to be).
So if I hold down the right arrow key, I only move 5 pixels every 2 seconds.
How do I combat this? Did I do something wrong(obviously but is it related to how I set up the variables or what)? If you need to see any of my other code let me know.
 
R

Rustic Penguin

Guest
There's probably a better way to do it, but this should fix the problem.

// Put this part in the create of the player
entrance = 1

if ((room = rm_ghost1) && (entrance = 1))
{
can_move = false;
entrance = 0;
alarm[0] = 120;
}
 
S

sjschindler

Guest
I will not make the same mistake I did last time when i had a problem.

To all of you, thank you so much for your efforts and advice. The problem is fixed, and my game is running perfectly again. Mad respect for all of you!
 
Top