A
AX53
Guest
I'm making a sidescroller platformer engine but I've run into a strange problem. This might be a somewhat advanced question.
The initial collision detection / motionstopper works brilliantly. When I reach the DIY raycast which is essentially a for loop acting as a pixel perfect raycast, it doesn't seem to function at all.
What happens?
The character falls until the motionstopper takes place. yspeed is reset and it falls 1 pixel everytime yspeed reach 1 until it stops at the ground.
So what should happen?
After the motion stopper has taken place and initially detected the ground and turned the velocity to 0, the raycast part should move the object into contact with the ground. It does this by checking pixel by pixel for collisions downwards until it finds the ground and moves the character down the same amount of loops it's taken so far. (yes the collision mask is a 1x1 pixel sprite). But it doesn't seem to at any time find a collision even though the exact same function works flawlessly earlier on in the code.
Keep in mind that i've set terminal velocity to 8, and each collision block is 16x16 so its impossible for the character to skip trough the ground.
Any idea what I'm missing?
The initial collision detection / motionstopper works brilliantly. When I reach the DIY raycast which is essentially a for loop acting as a pixel perfect raycast, it doesn't seem to function at all.
What happens?
The character falls until the motionstopper takes place. yspeed is reset and it falls 1 pixel everytime yspeed reach 1 until it stops at the ground.
So what should happen?
After the motion stopper has taken place and initially detected the ground and turned the velocity to 0, the raycast part should move the object into contact with the ground. It does this by checking pixel by pixel for collisions downwards until it finds the ground and moves the character down the same amount of loops it's taken so far. (yes the collision mask is a 1x1 pixel sprite). But it doesn't seem to at any time find a collision even though the exact same function works flawlessly earlier on in the code.
Keep in mind that i've set terminal velocity to 8, and each collision block is 16x16 so its impossible for the character to skip trough the ground.
Any idea what I'm missing?
Code:
//Gravity application
yspeed += 16/30;
if(yspeed>0)
{
//initial collision detection motion stopper
if(!place_free(x,y+round(yspeed)+8))
{
yspeed = 0;
//Diy raycast with ground contact movement
for(raylength = 0; raylength<round(yspeed)+8; raylength+=1)
{
if(!place_free(x,y+raylength))
{
y+=raylength-8;
break;
}
}
}
}
//Velocity application
y+=max(min(round(yspeed),8),-8);
Last edited by a moderator: