actionscript 3 - Gravity only working after a keystoke AS3 -


here problem, new programming , following tutorial learn random things. have gotten work far except gravity. when run program player floating, when hit "down" key gravity takes effect.. can't figure out why.

if(leftbumping){     if(xspeed < 0){         xspeed *= -0.5;     } }  if(rightbumping){     if(xspeed > 0){         xspeed *= -0.5;     } }  if(upbumping){     if(yspeed < 0){         yspeed *= -0.5;     } }  if(downbumping){     if(yspeed > 0){         yspeed *= 0.0;     }     }  else {         yspeed += gravityconstant; } 

i have trace on bumping collisions , work properly. if in open space detect no collision, , when touching walls output shows am. iv been reworking these lines hours. please help

this may also

if(apressed){     xspeed -= speedconstant;  } else if (dpressed){     xspeed += speedconstant;  }  if (wpressed){     yspeed -= speedconstant;  } else if(spressed){     yspeed += speedconstant; } if(leftbumping){     if(xspeed < 0){         xspeed *= -0.5;     } } 

you need stick bit:

yspeed += gravityconstant; 

into function called every frame, this:

this.addeventlistener(event.enter_frame, onenterframe)  private function onenterframe(e:event):void {     yspeed += gravityconstant; } 

if happening quickly, either need reduce gravity constant, reduce fps, or use timer rather enterframe.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -