flash - actionscript 3 wall hit-detection -


am making simple flash game , trying keep avatar hitting walls in given level, here code wrote, simple enough

       var hitwall:boolean = checkwallhitlvl1();            if ( downkeyisbeingpressed  )             {                 avatar.moveabit( 0, 1 );                 if(hitwall)                 {                     avatar.moveabit( 0, -5);                  }              }             else if ( upkeyisbeingpressed  )             {                 avatar.moveabit( 0, -1 );                 if(hitwall)                 {                     avatar.moveabit( 0, 5 );                  }              }                else if ( leftkeyisbeingpressed  )             {                 avatar.moveabit( -1, 0 );                 if(hitwall)                 {                      avatar.moveabit( 5, 0 );                   }              }             else if ( rightkeyisbeingpressed )             {                 avatar.moveabit( 1, 0 );                 if(hitwall)                 {                     avatar.moveabit( -5, 0 );                  }              }    

hitwall checks if avatar hits level's walls, problem code if hit wall right, , trying move left, cant since hitwall doesn't check wall hit, question is there way make work without needing figure out direction player hits given wall, tried moving avatar automatically left if hits right, didn't quite work out well...

any suggestions please?

thanx =d

edit1: edited code, works now, looks kinda jerky since have step backwards 5 pixels, cannot step backwards 1 pixel unfortunately since, since flash's hittestobject still returns true (checkwallhitlvl1() uses hittestobject check if player hits wall), suggestions?

edit2: found way fix it, need run more tests , make sure works fine, if pass post code up, used 4 boolean variables check direction hit wall, , went there...=d

what keep position of when not hit.

    if ( downkeyisbeingpressed  )         {             avatar.moveabit( 0, 1 );             if(hitwall)             {                 avatar.moveto(safex, safey);              } else {                 safex = x;                 safey = y;         } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -