Legacy GMZelda-like sliding off a diagonal Wall OR Layers again.

M

McWolke

Guest
Hey there,

I am working on a top-down Adventure Game, just like Zelda, and right now i am using the built in physics system.
Now i'd like to change it to non-physics and still have the same collision behavior like the physics system, because i have some problems with the physics system (maybe i could fix that, but i have no idea how). what i am trying to do is this wall-sliding-thing when walking against a diagonal Wall: https://i.gyazo.com/e0be30ee354fd704d26d79cd468dd080.gif

i haven't programmed anything yet (still thinking about it if i really should change everything to non-physics) so i can't really show any code to fix here. I just want the idea behind it how it works, so i can code it by myself.

Alternatively:

the idea was to give everything a variable "layer" and only to collide with something if the variable "layer" equals the "layer" variabe of the other object.
but with the physics system i can not disable a collision depending on a variable, can i?
so like when the player is on layer 1 and there is a Wall on layer 2, how would i do it that the player still can walk trough it, but everything on layer 2 can't (like enemies on layer 2)?

if there is a solution for the physics system problem i would be glad, but i can also change everything back to non-physics, if i have to.

Roa

Member
Don't ever use physics unless you know your game requires it. You can and should do all this with just normal collision checking. Checking diagonals is easy, you simply check ahead, and if you are blocked, check a little to the right or left and if its not, set the motion to go a little left or right.

M

McWolke

Guest
Don't ever use physics unless you know your game requires it. You can and should do all this with just normal collision checking. Checking diagonals is easy, you simply check ahead, and if you are blocked, check a little to the right or left and if its not, set the motion to go a little left or right.
yeah.. but it was definitly easier with physics until now. :/
ok that was kinda obvious i'll just make a copy of my current project and change everything really quick now and come back if i have any issues. thank you!

TheouAegis

Member
You could even do the layers using nothing but tiles and a collision map.

And with the diagonal wall sliding, it basically works like this from what I can tell:
• Each slope is designated a direction (e.g., 1 = up-left to down-right open on up-right, 2 = down-left to up-right open on down-right, 4 = up-left to down-right open on down-left, 8 = down-left to up-right open on the up-left)
• If moving right, if the slope is open on the right, you move vertically in the leftward direction (e.g., if the slope has a value of 1 from the example above, then you'd walk up; if the slope has a value of 2, you'd walk down), otherwise you move vertically in the rightward direction. The opposite is the case when moving left.
• If moving up, if the slope is open on the top, you move horizontally in the downward direction, otherwise you move vertically in the upward direction. The opposite is the case when moving down.

M

McWolke

Guest
alright, so i changed the most to non-physics now and made a movement script:
Code:
``````var xspeed = argument0;
var yspeed = argument1;

//Check if i can walk without any collision
if(!place_meeting(x+xspeed,y+yspeed,obj_Solid)){
x += xspeed;
y += yspeed;
} else {
//I've Collided..
if(xspeed != 0){
//Check if i can walk horizontal when i also walk the same speed vertical
if(!place_meeting(x+xspeed,y+xspeed,obj_Solid)){
x = x+xspeed;
y = y+xspeed;
} else if(!place_meeting(x+xspeed,y-xspeed,obj_Solid)){
x = x+xspeed;
y = y-xspeed;
}
} else if (yspeed != 0){
//Check if i can walk vertical when i also walk the same speed horizontal
if(!place_meeting(x+yspeed,y+yspeed,obj_Solid)){
x = x+yspeed;
y = y+yspeed;
} else if(!place_meeting(x-yspeed,y+yspeed,obj_Solid)){
x = x-yspeed;
y = y+yspeed;
}
}
}``````
it works quite well if there is only 1 obj_Solid but as soon as there are many in a row the Player stops moving when he reaches the point where the obj_Solids overlap or touch, doesn't matter. but this does not happen everywhere.. but very often. i've also tried to give them all the same scaling (1x and 0,5x) or different scalings, no change. do i have something wrong in my code?

room looks like this (it looks like there is a 1 pixel gap between them, but there is none):

https://i.gyazo.com/2b202306056988ce1881176cb5ed9007.png

movement ingame looks like this:

(visible collisions: https://i.gyazo.com/e643b3bc96d6d58c64b2b341320e26aa.gif)

my player collision mask is a rectangle, but i also tried an ellipse.

EDIT: Fixed it! Rotating made it bugged. If i "rotate" it by SCALING it, it works!

Last edited by a moderator: