So, this is basic code for moving right and left and jumping. By all definition it should also include wall collision, but...when i collide with a wall i go right through it. I can stand on it fine, i dont fall through the floor. no matter how high, so long as the floor is thick enough. However i can jump through the ceiling, and g through walls to the left and right. Please i need an expert to read through this code and tell me if they can see any flaws with it, because i cant. But it still doesnt work, any idea on how to make it work, what i am missing. The syntax is perfect...
AS2 by the way.
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 7;
var maxJump:Number = -12;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y-(_height), true)) {
_y -= speed;
}
}