7331337 Posted February 22, 2015 Share Posted February 22, 2015 Right now I think I'm doing it in a really hacky way and I'd hope there would be better ways than doing it. Right now I'm basically doing; int rand1 = random(0, 10) - 5; int rand2 = random(0, 30) - 15; Position randomPath = new Position((baseObject.getX() + rand1), (baseObject.getY() + rand2), 0); if (map.canReach(randomPath)){ localWalker.map.walk(randomPath); } This is for getting into view of the object itself so it can be interacted with later. Would there be better ways than doing this to get to a object not yet visible but I have the known coord's for? Link to comment Share on other sites More sharing options...
Mysteryy Posted February 22, 2015 Share Posted February 22, 2015 (edited) 1) you are not generating a path, you are generating a position, a single position. 2) you are making the x and y positions have a variance, if you happen to generate a random position that is not walkable, then the if statement will not execute. 3) if the position is too far to walk to then it will do nothing. LocalWalker will not take you cross regions without a path unless the region is cached, then it might (depends on client implementation). If you are trying to walk a path, you need to give it a path. This will walk from one single point (the player) to the sudo random position that you are generating within the same region. If that is what you want to do then this will kind of work maybe sometimes. Edited February 22, 2015 by Mysteryy 1 Link to comment Share on other sites More sharing options...
7331337 Posted February 22, 2015 Author Share Posted February 22, 2015 1) you are not generating a path, you are generating a position, a single position. 2) you are making the x and y positions have a variance, if you happen to generate a random position that is not walkable, then the if statement will not execute. 3) if the position is too far to walk to then it will do nothing. LocalWalker will not take you cross regions without a path unless the region is cached, then it might (depends on client implementation). If you are trying to walk a path, you need to give it a path. This will walk from one single point (the player) to the sudo random position that you are generating within the same region. If that is what you want to do then this will kind of work maybe sometimes. Was a quick example not actually what I use >.> the random position is run in a while loop until it finds a correct one and the area this used is in its own sub-area of the map like minigames. I'd like to however be able to fix your 3rd point out of it not working if its too far away which is what I want to resolve by generating a path to that position. Link to comment Share on other sites More sharing options...
Apaec Posted February 22, 2015 Share Posted February 22, 2015 Perhaps what you might find easier is having a handful of pre-recorded paths, maybe 2 or 3, each slightly different, and when walking the path it would pick a random one of the three each time. As far as randomisation goes, that's not a too bad way of doing it, and its nice and simple too Apaec 2 Link to comment Share on other sites More sharing options...
Mysteryy Posted February 22, 2015 Share Posted February 22, 2015 Was a quick example not actually what I use >.> the random position is run in a while loop until it finds a correct one and the area this used is in its own sub-area of the map like minigames. I'd like to however be able to fix your 3rd point out of it not working if its too far away which is what I want to resolve by generating a path to that position. What you are asking goes far beyond a simple explanation. I would suggest doing what apaec said, you should start with defining some paths and pick between them. On a side note, if you have a while loop generating the random position until it gets one that is walkable, you may get stuck in an infinite loop where there is never a walkable tile. Generally speaking while loops arent a great thing to use in scripts. I try to avoid them most of the time, and when I do use them I always add a watchdog timer. 1 Link to comment Share on other sites More sharing options...