I’m working on collision on my game and I found that it was spazzing out. Here is my code:
if ( collide( "level", x, y + v.y ) )
{
if ( v.y > 0 )
{
// Moving down.
trace( "test" )
v.y = 0;
y = Math.floor( y / 32 ) * 32 + 32 - height;
}
else
{
// Moving up.
v.y *= -.7;
y = Math.floor( y / 32 ) * 32 + 32;
}
}
else
{
trace( "test2" )
}
y += v.y;
Basically even if I’m sitting on the ground not moving, in my output box it alternates from test2 to test and back and forth. I can’t seem to find a reason for this. Any ideas?
E: Fixed it with a semi-ugly solution.
for ( var j:int = 0; j < Math.abs( v.y ); j++ )
{
if ( collide( "level", x, y + FP.sign( v.y ) ) )
{
if ( v.y > 0 )
{
// Moving down.
touchingGround = true;
v.y = 0;
break;
}
else
{
// Moving up.
v.y *= -.7;
}
}
else
{
y += FP.sign( v.y );
touchingGround = false;
//break;
}
}