So I've created a pretty short bit of code that handles slopes in almost the same way as Yoshi's Island. the only problem is that the game now thinks that ledges are slopes too and warps the player down almost halfway, and by halfway I mean a couple hundred pixels? (I think it's whatever I set my maximum slope variable too.)
Here's the code:
EDIT: Sorry I forgot to explain some of the variables in the code. I've used cd and cu to describe how many pixels to move down or up respectively, and Hsp is horizontal speed. Solid is a constant I made to reference the collision object. I think that's it...
Code:
slope_max = 10
if !place_meeting(x+sign(Hsp),y,Solid)
{
for (cd=0; !place_meeting(x+Hsp,y+cd,Solid) && cd<=abs(slope_max); cd+=1;)
{
if !place_meeting(x+Hsp,y+cd,Solid) and place_meeting(x,y+slope_max,Solid)
y+=cd;
}
//while ((!place_meeting(x+Hsp,y+cd,Solid) && cd <= abs(slope_max))) cd += 1;
}
if place_meeting(x+Hsp,y,Solid)
{
cu = 0;
while ((place_meeting(x+Hsp,y-cu,Solid) && cu <= abs(slope_max)))
//or
//((place_meeting(x+Hsp,y+c,Solid) && c <= abs(slope_max)))
cu += 1;
if place_meeting(x+Hsp,y-cu,Solid)
{
while (!place_meeting(x+sign(Hsp),y,Solid)) x+=sign(Hsp);
Hsp = 0;
}
else
{
y-=cu;
}
}
x += Hsp;
This is the entire collision code. it's inside of a script so I can call it whenever an object needs to.
It's also loosely based off of Shaun Spalding's collision code from his platformer tutorial.
if anyone could help with this I would greatly appreciate it. I am still working on it so I guess if I fix it before I get a reply I'll just, idk reply to this? (This is the first time I've used this site in years)
So I've created a pretty short bit of code that handles slopes in almost the same way as Yoshi's Island. the only problem is that the game now thinks that ledges are slopes too and warps the player down almost halfway, and by halfway I mean a couple hundred pixels? (I think it's whatever I set my maximum slope variable too.)
Here's the code:
EDIT: Sorry I forgot to explain some of the variables in the code. I've used cd and cu to describe how many pixels to move down or up respectively, and Hsp is horizontal speed. Solid is a constant I made to reference the collision object. I think that's it...
[code]
slope_max = 10
if !place_meeting(x+sign(Hsp),y,Solid)
{
for (cd=0; !place_meeting(x+Hsp,y+cd,Solid) && cd<=abs(slope_max); cd+=1;)
{
if !place_meeting(x+Hsp,y+cd,Solid) and place_meeting(x,y+slope_max,Solid)
y+=cd;
}
//while ((!place_meeting(x+Hsp,y+cd,Solid) && cd <= abs(slope_max))) cd += 1;
}
if place_meeting(x+Hsp,y,Solid)
{
cu = 0;
while ((place_meeting(x+Hsp,y-cu,Solid) && cu <= abs(slope_max)))
//or
//((place_meeting(x+Hsp,y+c,Solid) && c <= abs(slope_max)))
cu += 1;
if place_meeting(x+Hsp,y-cu,Solid)
{
while (!place_meeting(x+sign(Hsp),y,Solid)) x+=sign(Hsp);
Hsp = 0;
}
else
{
y-=cu;
}
}
x += Hsp;
[/code]
This is the entire collision code. it's inside of a script so I can call it whenever an object needs to.
It's also loosely based off of Shaun Spalding's collision code from his platformer tutorial.
if anyone could help with this I would greatly appreciate it. I am still working on it so I guess if I fix it before I get a reply I'll just, idk reply to this? (This is the first time I've used this site in years)