William Garrison
Member
So recently I decided to gut a game I have been working on for off/on a couple years. Started from scratch and am porting in code from the old one to the new one, one object at a time or as needed. So I can weed out the crap. Going great. BUT once I got the player movement code in this issue presented itself. When I run left/right the player rapidly cycles between a single pixel. See the gif below. This is the same code that works great in the other version but this version does not. Its baffling me. I have adjusted origins and removed this and that trying to find the culprit to no avail.
(hero Y) and (grounded) show what's occurring. It couses the vertically "vibrate" the character.
Here is the collision code.
(hero Y) and (grounded) show what's occurring. It couses the vertically "vibrate" the character.
Here is the collision code.
GML:
// Horizontal Collision
if (place_meeting (x + hsp, y, allCollide))
{
yplus = 0;
while (place_meeting(x+hsp,y-yplus,allCollide) && yplus <= abs(1*hsp)) yplus += 1;
if place_meeting(x+hsp,y-yplus,allCollide)
{
while (!place_meeting(x + sign(hsp), y, allCollide))
{
x = x + sign(hsp);
}
hsp = 0;
}
else
{
y -= yplus;
}
}
x = x + hsp;
// Vertical Collision
if (place_meeting (x , y + vsp, allCollide))
{
while (!place_meeting(x , y + sign(vsp), allCollide))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
if (vsp != 0) grounded = false; else grounded = true;