In the end of the last post we had a problem where the character vibrated. This was because when ever the character touched the floor i made it move up by one pixel. to rectify this i will make another hittest that detects when the character is one pixel off the floor and only calculate the velocity of the player if it returns false.
-
<span style="color: #666666;">function run(event:Event) {</span></div>
-
<div><span style="color: #666666;"> velocity+=gravity;
-
if (land.hitTestPoint(char.x, char.y+char.height/2, true)) {
-
velocity = 0;
-
char.y--
-
}
-
if (!land.hitTestPoint(char.x, char.y+char.height/2+1, true)) {
-
char.y += velocity;
-
} else {
-
velocity=0;
-
if (attemptJump==true) {
-
char.y--;
-
velocity =-5;
-
}
-
}
-
if (goleft==true) {
-
char.x+=lspeed;
-
}
-
if (goright==true) {
-
char.x+=rspeed;
-
}
-
}


