# Grab coins with moveXY almost as with move boots

Inspired by Move method stuttering when MoveXY does not post I tried about half an year ago to rewrite the same function. You grab the coins at arm’s length. I think if the coef can be changed to other near values depending maybe from the hero’s speed, the boots used or the presence of the speed ring. The function may be used also when fighting enemies. You can also use the fastest 2.5 m/s moveXY boots but I have no definitive conclusion about the gain in speed. After some time I switched to the boots of leaping and forgot about this, but will be glad if someone use the function and share comments or hopefully improvements.

``````coef = 3
def moveToXY(goalPoint):
goal = Vector.subtract( hero.pos, goalPoint)
goal = Vector.normalize(goal)
goal = Vector.multiply(goal, coef)
hero.moveXY(moveToPos.x, moveToPos.y )
# call
if coin:
moveToXY(coin.pos)
``````
4 Likes

A nice improvement for the moveXY approach with some limitations. This works great when there is an object to give you the position. I was using this in Flawless Pairs and it works for the gem pairs, but not moving back to the X. I had to keep the regular moveXY for that part.

Sample code for Flawless Pairs
``````    if gemPair:
gemA = gemPair[0]
gemB = gemPair[1]
# Move to the first gem.
moveToXY(gemA.pos)
hero.moveXY(40, 44)
# Then move to the second gem.
moveToXY(gemB.pos)
hero.moveXY(40, 44)
pass

``````
Coordinates don't work {"x": 40, "y": 44}

I can’t get it to work when I’m giving coordinates like you can with move.
`moveToXY({"x": 40, "y": 44}) # does not work`

I get an error:
TypeError: e.copy is not a function

The `coef = 3` is the max you want for picking up items. I tried pushing it and some heroes started missing the gem at 3.3. I tried all the heroes I have and they all work at 3. Only other downfall, like moveXY, it won’t let you run any other code until you reach your goalPoint - coef.

When attacking enemies, I’d have the coef variable look at the attackRange or throwRange (add the coef as a parameter). Otherwise, you walk right into the enemy range before you begin to attack. I think it might work great in the multiplayer combat if your pair this with your attack to ensure you move into attack range before calling the attack method. I’ve run into this problem quite a big; calling the attack method when out of attack range, the enemy goes invisible as the hero moves into attack range (likely using the moveXY method behind the scenes) and then my hero wanders around aimlessly because it didn’t complete the attack and is stuck on the method.

1 Like

Thank you for the thorough testing! I will read all you remarks a bit later.
As for {“x”: 40, “y”: 44}. The function didn’t know this is a Vector. I never use this notation for coordinates, It easier for me to type moveToXY(Vector(40, 44)) - it will work. And the name of the function is misleading - maybe cheapBootsMoveToPos(vector) ?

Edit: Credit to Shurutsue for renaming the function to altMove. I rewrote it in javascript to be as close to hero.move(vector):

``````hero.altMove = function (goalPoint, coef){
if(coef === undefined) coef = 3;
var goal = Vector.subtract( hero.pos, goalPoint);
goal = Vector.normalize(goal);
goal = Vector.multiply(goal, coef);