actionscript 3 - AS3 landing smoothly under affect of Gravity -


i'm attempting make fighting game multiple platforms. i've made controls, movement, (double)jumping, , gravity parts of game.

the issue is, when player jumps, upon reaching ground, seem go bit deeper should on platform (they should land , stay on surface of platform). more visible when player double jumps.

i know why happens; it's because hittestobject takes while react when objects come in quickly.

so, first thing thought of make player's foot's y axis equal y axis of top of platform lands on.

though, solution resulted in rather jerky landing.

my question is: there way make player land smoothly on top surface of platform?

some things i've tried:

-raising fps, made same effect happen, more quickly.

-decreasing speed @ player falls, but makes game less fun, i've crossed out.

and here's relevant code:

stage.addeventlistener(event.enter_frame, loop); var jumpconstant:number = 30; var gravityconstant:number = 1.8; function loop(e:event):void //happens  {     if(player.leg1.foreleg1.foot1.hittestobject(platforms.ground)||player.leg2.foreleg2.foot2.hittestobject(platforms.ground)) //if either of player's legs colliding platform [ps: nested movieclips]     {         player.yspeed = 0; //the player stops going downwards         player.y = platforms.y; //the player's y becomes platform's y. don't worry, puts player in right place, not smoothly.         if (player.b_up) //if control button (w or arrow) being pressed         {             player.yspeed = -player.jumpconstant; //make player jump          }     else //if player isn't colliding platform     {         player.yspeed += player.gravityconstant; //the player affected gravity , pulled downwards     } 

link game if wanna try out see jerky effect:

http://www.fastswf.com/-64ux3i

the problem checking collision @ increments of yspeed. since y speed increases during fall 1.8 per step, looking @ collision checks spaced apart. if want pixel precise collision checks, need check collision @ 1px increments. means if y speed 10, need 10 collision checks during 1 loop update. use loop within loop function accomplish this.


Comments