Find nearest object on a path?

  • Testing it here with a Galasy S3 resulted in excellent result, but on low end devices it might lag.

    The pathfinder will run once when the player move, so, you can setup a popping board saying something like "Waiting movement" when the CPU usage become more than a % (you can verify it under the system variables, and compare it), like in old turn based games (Xcom Apocalypse, etc).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • TELLES0808, how does your example apply to multiple player objects? I think your implementation is probably the best one for my usage but I'm having issues adapting it for multiple entities owned by the player.

    And I definitely agree with your suggest to

  • It can be done by setting the objects to find a path for each player entity, in order, and store the results inside an array or variable.

    To store it inside a variable, first check if the result is bigger than the actual, if not, set the value, otherwise, skip and leave the variable as it is.

    To store it inside arrays (and maintain a history, being able to rollback the game could be a nice feature), you can sort the cells and pick the lowest result.

    Look how awesome is the effect created using array:

    dl.dropboxusercontent.com/u/4756521/Construct%20Demos/Record%20And%20Rewind/index.html

    dropbox.com/s/aisj9jgctawhyvu/TimeRecordAndRewind.capx

  • TELLES0808, I have implemented something similar to what you described earlier, basing my events off of the wonderful

    However, I am having problems getting my arrays to actually fill out. Here's what happens in my events:

    Each time a computer object is spawned (three spawn in my game), an instance of an array called enemyDistance is created. The UID of this array is then assigned to the arrayUID instance variable of the computer object. Since 3 computer objects are spawned, there are 3 instances of this array and each one is assigned to 1 computer object.

    The enemyDistance array is set to have a height equal to the number of player objects on the board. The idea is to use pathfinding's find path to calculate the distance from the computer object to each player entity. After all the distances (the UIDs of the objects are also stored) are calculated, the game is supposed to pick the closest one (based on path and not actual distance, which is the whole point of this setup) and set it as its target.

    However, right now the distances aren't being computed for some odd reason, so all the distances stored are equal to zero. Can someone take a look and help me out?

    <img src="http://i.imgur.com/6eV7Vaq.png" border="0">

    Relevant events:

    <img src="http://i.imgur.com/ZivGRqz.png" border="0">

    <img src="http://i.imgur.com/ue0uqdG.png" border="0">

    BoardGame.capx

  • I think I almost have it. Distances are calculated now, but sometimes the game seems to hang in calculation. In other words, in the debugger I see 'calculating path' constantly change from true to false and the 'activity' variable (which tells what the object is currently doing) change from 'action' (meaning paths have been calculated) to 'path' (which is when it is calculating paths).

    However, I'm not sure why there is sometimes a failure to determine distance.

    Definitely agree with TELLES0808 on the suggestion for a 'path distance' expression of some kind that will let us derive the distance from a calculated path. I'll post in the general forum as a suggestion.

  • Excal,

    Sometimes, my objects collide with solids and it turn them unable to calculate any route, try setting them smaller (only the collision polygon, not the image)

  • TELLES0808, that doesn't seem to be the issue here (I set the size smaller).

    However, I think I have found one possible reason why it hangs - if in the case there are two or more objects with equal distance, the game fails to identify which is shortest.

  • Nevermind, apparently that isn't the issue either.

    I'm not sure what is going on. The computer object keeps alternating between calculating path true and calculating path false, causing a hang.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)