Alexir
Member
I'm creating a top down shooter, and I want walls that keep the player from going out of bounds. I've got some code set up that works pretty fine:
(Keep in mind, my player character is named Eddy)
//up and left
if(place_meeting(x+eddyspeed,y,obj_wall))
{
obj_Eddy.x = obj_Eddy.x - 5
}
if(place_meeting(x,y+eddyspeed,obj_wall))
{
obj_Eddy.y= obj_Eddy.y - 5
}
//down and right
if(place_meeting(x-eddyspeed,y,obj_wall))
{
obj_Eddy.x = obj_Eddy.x + 5
}
if(place_meeting(x,y-eddyspeed,obj_wall))
{
obj_Eddy.y= obj_Eddy.y + 5
}
It's a bit messy but works, except for the fact that sometimes the player character can diagonally clip through the wall by accident, which is obviously not something I want. I only have 1 speed variable, being eddyspeed, and not distinct ones for horizontal and vertical movement, so many of the other tutorials don't apply to me. Is there any cleaner method of getting this accomplished, or perhaps just a solution to the glitch? Any help is appreciated.
(Keep in mind, my player character is named Eddy)
//up and left
if(place_meeting(x+eddyspeed,y,obj_wall))
{
obj_Eddy.x = obj_Eddy.x - 5
}
if(place_meeting(x,y+eddyspeed,obj_wall))
{
obj_Eddy.y= obj_Eddy.y - 5
}
//down and right
if(place_meeting(x-eddyspeed,y,obj_wall))
{
obj_Eddy.x = obj_Eddy.x + 5
}
if(place_meeting(x,y-eddyspeed,obj_wall))
{
obj_Eddy.y= obj_Eddy.y + 5
}
It's a bit messy but works, except for the fact that sometimes the player character can diagonally clip through the wall by accident, which is obviously not something I want. I only have 1 speed variable, being eddyspeed, and not distinct ones for horizontal and vertical movement, so many of the other tutorials don't apply to me. Is there any cleaner method of getting this accomplished, or perhaps just a solution to the glitch? Any help is appreciated.