P
player_2
Guest
Hi guys! I am newbie and I need your help. Recently I started making a game in GMS2 and ran into a couple of questions that I couldn’t find answers to:
1.There is an object that moves along the platform, reaches the edge and turns around in the opposite direction. it works like this:
Such a code has many disadvantages - if the hole is less than the width of the sprite of the object, then it will not notice it and will move on. Also, if i change the direction of the sprite depending on the direction of movement (image_xscale), the code starts to work incorrectly:
How to check the lack of a platform ahead? It seems that for 2d platformers this is a fairly common situation and the solution should be simple.
2. Same case, but I still need to find out the ID block on the edge of the platform . if I do it this way ( the color of the block changes for clarity)
the code does not work correctly - on one side of the platform, the color changes at the desired block, on the other side - at the penultimate block:
How to do it right? (sprite origin for all objects is in the center)
1.There is an object that moves along the platform, reaches the edge and turns around in the opposite direction. it works like this:
Code:
var hspd = movespeed*dir;
if(!place_meeting(x+ sign(hspd)*sprite_width+ hspd, y+1, oSolid))
{
while(place_meeting(x + sign(hspd)*sprite_width + sign(hspd), y+1,oSolid))
{
x+= sign(hspd);
}
hspd = 0;
dir *= -1;
}
x+= hspd;
Such a code has many disadvantages - if the hole is less than the width of the sprite of the object, then it will not notice it and will move on. Also, if i change the direction of the sprite depending on the direction of movement (image_xscale), the code starts to work incorrectly:
How to check the lack of a platform ahead? It seems that for 2d platformers this is a fairly common situation and the solution should be simple.
2. Same case, but I still need to find out the ID block on the edge of the platform . if I do it this way ( the color of the block changes for clarity)
Code:
var hspd = movespeed*dir;
if(!place_meeting(x+ sign(hspd)*sprite_width + hspd, y + 1, oSolid))
{
while(place_meeting(x + sign(hspd)*sprite_width + sign(hspd), y+1, oSolid))
{
x+= sign(hspd);
}
hspd = 0;
dir *= -1;
var inst = instance_place(x,y+1, all); // this string
inst.image_blend = c_red;
}
x+= hspd;
How to do it right? (sprite origin for all objects is in the center)