Actionscript 3 Movieclip To Repel The Mouse Cursor
I'm trying to build an application where the themouse cursor is used to "blow" a movieclip around. The way I'm doing this is by making the mouse cursor repel the movieclip.
The problem is, I can only get 开发者_StackOverflowit to work on the top and the left of the movieclip.
Here's my code:
function moveCloud(event:Event):void {
var yChange:Number = Math.round(mouseY-cloud.y);
var xChange:Number = Math.round(mouseX-cloud.x);
//var yMove:Number = Math.round(yChange);
//var xMove:Number = Math.round(xChange);
var dist:Number = Math.sqrt(xChange*xChange + yChange*yChange);
trace(dist);
if(dist < 100)
{
var angle:Number = Math.atan2(yChange, xChange);
cloud.y += Math.cos(angle)*2;
cloud.x += Math.sin(angle)*2;
}
Anyone done something like this before or have any ideas?
Just change sine and cosine and substract it instead of adding.
cloud.x -= Math.cos(angle);
cloud.y -= Math.sin(angle);
精彩评论