Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Hero never stops "moving"


Keep in mind that i’m still learning some stuff about codding, so if there’s some obvious answer i’m not seeing, please let me know :P.

So in dungeon arena, i’m trying to get my Hero to move to a specific position, and then do something once he gets there, but the problem is, he technically never “gets” there.

i’m using the command “this.move({x:,y:});” to get him to move somewhere, but once he reaches that position, he just plays the walking animation endlessly.

i have a statement that says “if(this.pos == {x:,y:}){dostuff}” but nothing happens when he gets there, he just plays an endless walking animation at the position.

what am i missing?


Describe the endless walking animation? In what direction is he walking? Towards something? Straight forward? Moving in place?

As far as it goes, I think there might be an infinite loop somewhere, or perhaps a condition that you make him walk on that is always true. I assume your code looks something like:

if(conditionToMove) {
    this.move({x:30, y:30});

You may be forgetting to alter the condition to be false so that the next iteration of your code detects that it is false and appropriately skips it. If you never change the condition, you’ll always move there, even if he’s already there.

If not, providing more details would help. It would be easiest if we could see the entire code to see what’s happening (maybe via PM if you don’t want to post it).


I’m doing something like this.

if( < 100){
if(this.pos == {x:30,y:30}){

not exactly like this, just an example.

If the hero’s health gets to this point, they will move the the position, but once they reach the position (30,30), the hero will continue to play the moving animation in the same direction they were going in, as if they were still moving to the coordinates.


Maybe try something like this:

if( < 100){
  if(this.pos == {x:30,y:30}){
  } else {


The problem here is that JavaScript == will not compare two different pos objects like that, even if the x and y are the same. (In fact, this.pos is a CodeCombat Vector and not a plain {x:, y:} Object.) Also, even if it could, this.pos will probably not exactly be at {x: 30, y: 30}, but rather just very close to it (like {x: 30.0052593625, y: 29.926367377}), since x and y are both floating point numbers.

Try using something like this:

if (this.distance({x: 30, y: 30}) < 1)


Alright, i tested that out, and it works great!


Additional tip: I would recommend you think about how you want to deal with push from friendly or enemy troops. If you want to stay shielded, you may want to increase the distanceTo test beyond 1…

Also, sometimes running away beats shield. Some folks refer to the ancient art of running around in circles, screaming while trying to stay alive as kiting. If you’re fast enough, you may also be able to cast while doing the circles…