
metadata
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 semiugly 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;
}
}
`


metadata
Why you us the **v.y** in **if(collide(“level”, x, y + v.y)){…}**?
An entity that is collideble has a hitbox, and it colides every time the hitbox is touching the wall! So **if(collide(“level”,x,y)) {…}** is enough, the x and y gives you only the coordinates, where your entity is at the collision. Or did you want something special with the “+ v.y” in the ifstatement?
