actionscript 3 - Hit test with line -


so i'm making platformer style game , trying make hit test line if makes sense. right have object moves around , whenever you're moving right, if lower right or upper right side hit world stop moving. same thing set left. works if "world" movieclip small , doesn't hit of points can go right through it. need make solid line between points , have hittest that?

else if (keyisdown(keyboard.right))         {             //dude.gotoandstop("right");             //obj.scalex = 1;             (i = 0; i<speedx; i++)             {                 obj.x++;                 dude.ball.rotation++;                 if (status == "ground")                 {                     dude.height+= 0.05;                     dude.width += 0.05;                  }                     if (world.hittestpoint(obj.x + obj.width/8 - obj.width/2, obj.y - obj.height/4,true) || world.hittestpoint(obj.x + obj.width/2,obj.y - obj.height + obj.height/4,true)) //this dictates points hit, trying make test hit solid line between 2 points.                     //if (world.hittestobject(dude.hitd))                     {                          dude.ball.rotation--;       obj.x--;                     break;                 }             }         }         dude.gotoandstop(1);      } 

line code tried adding

else if (keyisdown(keyboard.right))         {             //dude.gotoandstop("right");             //obj.scalex = 1;             (i = 0; i<speedx; i++)             {                 obj.x++;                 dude.ball.rotation++;                 myshape.graphics.moveto(obj.x + obj.width/8 - obj.width/2,obj.y - obj.height/4);                  myshape.graphics.lineto(obj.x + obj.width/2, obj.y - obj.height + obj.height/4);                 // number in obj.y-4 affects climbing ability                 if (status == "ground")                 {                     //dude.height+= 0.05;                     //dude.width += 0.05;                 }                   if (obj.hittestobject(myshape))                 {                     dude.ball.rotation--;                     obj.x--;                     break;                 }             }         }         dude.gotoandstop(1);      } 

as far can understand, trying make platformer game player controls ball. need circular collision detection, @ least going right , left.

while implementing kind of program, on parts executed often, collision detection, should looking shortcuts.

i can suggest couple approaches;

  1. shortcut case can having invisible box shape smaller ball, , making collision detection it. sure, reduce visual quality; e.g. when approach low edge can fit object's bottom left, object crash early, without visually touching block.

  2. or ignore performance , increase number of points around circle. can write algorithm find positions on outer edge of circle spacing, , check if of them colliding. way collision detection cannot miss small objects.

  3. however, there's better approach. can implement two-level collision detection. first have now, , second invisible box same height of ball, , smaller in width enough it's edges fall behind primary detection points. in way, secondary detection not miss anything, work when primary detection fails catch between or below.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -