What’s wrong with this code?
It glitches when I try different sides.
when I move “this.” I’m moving the map so the character looks like he is moving.
for (var i:int=0; i<fixedObjects.length; i++)
{
//verticle
if ((char.rightside > fixedObjects*.leftside) && (char.leftside < fixedObjects*.rightside))
{
if ((char.bottomside > fixedObjects*.topside) && (char.topside < fixedObjects*.topside))
{
//top walls
trace("topblocked");
this.y = this.y + (char.bottomside - fixedObjects*.topside);
char.y = fixedObjects*.topside - charH;
downArrow = false;
break;
}
else
{
//bottom walls
if ((char.topside < fixedObjects*.bottomside) && (char.bottomside > fixedObjects*.bottomside))
{
trace("bottomblocked");
this.y = this.y - (fixedObjects*.bottomside - char.topside);
char.y = fixedObjects*.bottomside + charH;
upArrow = false;
break;
}
else
{
//horizontile walls checking
if ((char.bottomside > fixedObjects*.topside) && (char.topside < fixedObjects*.bottomside))
{
// left wall
if ((char.rightside > fixedObjects*.leftside) && (char.leftside < fixedObjects*.leftside))
{
trace("leftblocked");
this.x = this.x + (char.rightside - fixedObjects*.leftside);
char.x = fixedObjects*.leftside - charW;
rightArrow = false;
break;
}
else
{
trace("other");
//right wall
if ((char.leftside < fixedObjects*.rightside) && (char.rightside > fixedObjects*.rightside))
{
trace("rightblocked");
this.x = this.y - (char.leftside - fixedObjects*.rightside);
char.x = fixedObjects*.rightside;
leftArrow = false;
break;
}
}
}
}
}