Pathfinding: add function

For developers using the Construct 2 Javascript SDK

Post » Wed Jul 16, 2014 8:59 pm

I think the pathfinding plugin need 1 more function: "Regenerate Path Of Map Obstacles", cause the default "Regenerate obstacle map" on huge maps make lags....
I wrote this(and of course it works):
Code: Select all
   
Acts.prototype.RegeneratePathOfMap = function (_position_x,_position_y,_radius)
   {
      var myinfo = this.getMyInfo();
      
      var arr = myinfo.cells;
      var x, y;
      _position_x = Math.floor(_position_x / this.cellSize);
      _position_y = Math.floor(_position_y / this.cellSize);
      var x1 = _position_x-_radius, x2 = _position_x+_radius;
      var y1 = _position_y-_radius, y2 = _position_y+_radius;
      for (x = x1; x <= x2; x++)
      {         
         for (y = y1; y <= y2; y++)
            arr[x][y] = this.queryCellCollision(x, y);
      }
      
      myinfo.cells = arr;
      myinfo.pathfinder["init"](this.myHcells, this.myVcells, arr, this.diagonalsEnabled);
      
   };

...
Code: Select all
AddNumberParam("PostionX", "Postion X");
AddNumberParam("PostionY", "Postion Y");
AddNumberParam("Radius", "Radius in cells");
AddAction(15, af_none, "Regenerate Path Of Map Obstacles", "", "New obstacles near [<i>{0}</i>, <i>{1}</i>] with radius <i>{2}</i> cells", "Regenerate Path Of Map Obstacles near point", "RegeneratePathOfMap");

i just put it here...
Last edited by iamskey on Thu Jul 17, 2014 8:55 am, edited 1 time in total.
B
3
Posts: 1
Reputation: 177

Post » Wed Jul 16, 2014 9:18 pm

Nice!
Founder of HeroicTek
HeroicTek.com
Owner of HeroicDomains
HeroicDomains.com
B
21
S
7
G
1
Posts: 157
Reputation: 2,020

Post » Thu Jul 17, 2014 11:08 am

Scirra Founder
B
399
S
236
G
89
Posts: 24,529
Reputation: 195,390

Post » Thu Jul 17, 2014 11:33 am

If this works it might just be the answer to all my AI prayers... I'll give it a go later!
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Thu Jul 17, 2014 11:38 am

@Ashley, if that's the case, please could this feature could be added to the official pathfinding plugin? My game would love pathfinding, but has huge maps and destructible terrain (so the obstacle map needs near-constant regeneration) so it's not really been an option til now. Or if there's a workaround for that situation, please let me know!
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Thu Jul 17, 2014 2:16 pm

Yes, it's on our todo list.
Scirra Founder
B
399
S
236
G
89
Posts: 24,529
Reputation: 195,390


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest