Hi,
I would need help with controling the speed like this:
When the mouse is moving closer to the square then the speed increases.
When the mouse is moving further from the square then the speed decreases.
Basicly the mouse following is done already i just need to put that speed controling
in place. Oh yeah and i have no clue why the square shakes when it hits the mouse.
Here is the code:
init();
function init():Void {
speed = 10;
var square = attachMovie(“square”, “square”, 0);
square._x = Stage.width/2;
square._y = Stage.height/2;
}
function onEnterFrame():Void {
var dx:Number = _xmouse-square._x;
var dy:Number = _ymouse-square._y;
var angle:Number = Math.atan2(dy, dx);
square._rotation = angle*180/Math.PI;
var vx:Number = Math.cos(angle)*speed;
var vy:Number = Math.sin(angle)*speed;
square._x += vx;
square._y += vy;
}
Thanx a lot,
Omicam