Hello i have this problem… My movieclip width and height are 69 and 59… and my registration point is at the center. So for colliding the bottom edge of the movie clip with the ground i have added the height along with the y variable. This just stops the movieclip at its edge when it touches the ground. Now my problem comes whenever i try to perform a jump action it does not work… whereas if i remove the height offset from the y variable the jumping works but the movieclip collides with the ground at its center that is it goes partially into the ground
this is my code
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 5;
var maxJump:Number = -18;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y+25, true)) // here if its _y it works {
_y -= gravity;
grav = 0;
}
if(ground.hitTest(_x,_y+25,true))
touchingGround=true;
else
touchingGround=false;
trace(touchingGround);
if(Key.isDown(Key.UP)&&touchingGround){
grav=maxJump;
}
}
I have also added the fla file… Please help me out