I’m experimenting with different control schemes for something I’m working on at the moment and I’ve currently made it so that a movieclip can follow my mouse cursor. My problem is that it comes and sits right on the point of the cursor (as it’s ‘supposed’ to). I’d like to have a radius of around 10px surrounding the cursor that the movieclip would stop at so that it heads towards the cursor but stops short. The only way I can think to do this would be with collision detection but that seems like a very clumsy route to take.
Here’s my code that moves the movieclip towards the mouse:
this is run on ENTER_FRAME
var dx:Number = stage.mouseX - this.x;
var dy:Number = stage.mouseY - this.y;
this._vx = Math.cos(Math.atan2(dy, dx)) * this._speed;
this._vy = Math.sin(Math.atan2(dy, dx)) * this._speed;
this.x += this._vx;
this.y += this._vy;
Why not use Pythagoras theorem to check the distance?