actionscript 3 - Converting complicated trigonometry from AS2 to AS3 -


i'm trying make game, following this tutorial.

the issue comes fact using actionscript 3.0 whereas tutorial written using actionscript 2.0.

regarding sight of enemy, have turned code:

onclipevent (enterframe) { dist_x = _root.hero._x-_x; dist_y = _root.hero._y-_y; dist = math.sqrt(dist_x*dist_x+dist_y*dist_y); angle = math.atan(dist_y/dist_x)/(math.pi/180); if (dist_x<0) {     angle += 180; } if (dist_x>=0 && dist_y<0) {     angle += 360; } wall_collision = 0; (x=1; x<=dist; x++) {     point_x = _x+x*math.cos(angle*math.pi/180);     point_y = _y+x*math.sin(angle*math.pi/180);     if (_root.wall.hittest(point_x, point_y, true)) {         wall_collision = 100;         break;     } } _root.line._x = _x; _root.line._y = _y; _root.line._rotation = angle; _root.line._alpha = 100-wall_collision; } 

into that:

// calculate rotation based on target _dx = this.x - _root.hero.x; _dy = this.y - _root.hero.y; // way rotate _rotateto = getdegrees(getradians(_dx, _dy));     // keep rotation positive, between 0 , 360 degrees if (_rotateto > barrel.rotation + 90) _rotateto -= 360; if (_rotateto < barrel.rotation - 90) _rotateto += 360;  // ease rotation _truerotation = (_rotateto - barrel.rotation) / _rotatespeedmax;  // update rotation barrel.rotation += _truerotation;     wall_collision = 0;  outerloop: (var xi=1; xi<=_dx; xi++) {     var point_x:number = this.x + xi*math.cos(_rotateto);     var point_y:number = this.y + xi*math.sin(_rotateto);      if(_root.wall.hittestpoint(point_x, point_y, true))     {         trace("hit");         wall_collision = 100;         break outerloop;     } }  _root.sight.x = this.x; _root.sight.y = this.y; _root.sight.rotation += _truerotation; _root.sight.alpha = 100 - wall_collision; 

but not work.

the rotation work fine, whole "alpha = 0 if player behind wall" not work.

please me resolving issue.

try following:

// calculate rotation based on target _dx = _root.hero.x-this.x; _dy = _root.hero.y-this.y;  // full distance missing as3 code _dist = math.sqrt(_dx*_dx+_dy*_dy);  // return old approach finding angle angle = math.atan(_dy/_dx)/(math.pi/180); if (_dx<0) {     _angle += 180; } if (_dx>=0 && _dy<0) {     _angle += 360; }  wall_collision = 0;  outerloop: (var xi=1; xi<=_dist; xi++) {     var point_x:number = this.x + xi*math.cos(_angle*math.pi/180);     var point_y:number = this.y + xi*math.sin(_angle*math.pi/180);      if(_root.wall.hittestpoint(point_x, point_y, true))     {         trace("hit");         wall_collision = 100;         break outerloop;     } }  _root.sight.x = this.x; _root.sight.y = this.y; _root.sight.rotation = _angle;  // alpha changed [0, 100] scale [0, 1] scale. _root.sight.alpha = (100 - wall_collision) * 0.01; 

information on alpha in actionscript 3.0.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -