Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] move(targetPos) doesn't work properly

sometimes when I use this function like this: hero.move({‘x’: 273, ‘y’: 37}), it just doesn’t work at all or just moves a couple of steps slowly and then stops, is there anything wrong?


Which level are you on? Also for some things it is better to use hero.moveXY(x, y) for example with coins or items because you need to go to specific place. The hero.move({‘x’: pos.x, ‘y’: pos.y}) it will execute other code as well that’s why only a few steps at a time. This is good if the object is moving or you need to do other things while moving to that position.

Hi, thanks for the quick response, I started to find this issue in the “mountain” world, but thanks for the tips, I’ll use hero.moveXY more often to deal with the items that don’t move, thanks

The difference:

hero.moveXY(50, 50);  // moveXY will block all other commands until it completes, so you will move to (50, 50) first, and only after you arrive will you attack enemies within range.  If you encounter an enemy as you are moving to position, you will ignore it.

hero.move({"x": 50, "y": 50}); // move is non-blocking, so you will move towards (50, 50), but will still be able to detect and attack enemies as you are moving to position.

great explanation, thank you!