K
Kodidro
Guest
Hi all
I'm fairly new to gamemaker and decided to try to make a short puzzle platformer to help expand my knowledge, I guess. Anyways, I'm trying to figure out how to make an object be "carried" by the player when you hold space, so I have it written as:
if(keyboard_check(vk_space))
{
while(distance_to_object(obj_player) < 25)
{
move_snap(obj_player,obj_player+22)
}
}
else
{
if (hsp < 10) vsp += grav;
if(place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y+=sign(vsp);
}
}
}
I have the variable for gravity as "grav" set up to apply my own fall speed. My goal is that when the player holds the space bar, the ball floats over the player like it's being "carried", and otherwise it falls to the ground as normal. The problem is that whenever I press space within 25 pixels, the game seems to freeze - I have to close the whole program to let me start up the game again. I assume there's some problematic interaction with my gravity setup though, because even if I take out the "while" bit I still can't get the object to move above the player.
Any suggestions how I could do this differently?
I'm fairly new to gamemaker and decided to try to make a short puzzle platformer to help expand my knowledge, I guess. Anyways, I'm trying to figure out how to make an object be "carried" by the player when you hold space, so I have it written as:
if(keyboard_check(vk_space))
{
while(distance_to_object(obj_player) < 25)
{
move_snap(obj_player,obj_player+22)
}
}
else
{
if (hsp < 10) vsp += grav;
if(place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y+=sign(vsp);
}
}
}
I have the variable for gravity as "grav" set up to apply my own fall speed. My goal is that when the player holds the space bar, the ball floats over the player like it's being "carried", and otherwise it falls to the ground as normal. The problem is that whenever I press space within 25 pixels, the game seems to freeze - I have to close the whole program to let me start up the game again. I assume there's some problematic interaction with my gravity setup though, because even if I take out the "while" bit I still can't get the object to move above the player.
Any suggestions how I could do this differently?