Stop a moveTo?

I set an gameObject moving by calling the physics.moveTo() function. How can I get it to stop moving once it gets to that point? I’ve tried setting the objects accelration to 0 after it starts, but that doesn’t seem to stop it at all…

I just added a collision and set the velocity to 0. Does the trick :wink:

I believe you can also use the reset function on the body to do this too - https://github.com/photonstorm/phaser/blob/master/src/physics/arcade/Body.js#L1221

Oh nice. That might work. I ended up doing it using simple vector math and it works fine, so I might leave it at that for now.

http://labs.phaser.io/view.html?src=src/physics/arcade/move%20and%20stop%20at%20position.js

This should be close enough to what to you’re looking for. moveTo and similar methods only set an appropriate velocity without stopping at the target. You should check the object’s distance from its target and stop its movement manually (like snowbillr suggested) if it’s close enough. That’s necessary because it will almost never reach the exact position - it’ll likely be fractions of a pixel (or, sometimes, more than a pixel) away because of the movement.

2 Likes