Avoid mouse

Hello,

as someone have a script to attach to mc´s, that avoids the mouse?

thanks


MovieClip.prototype.avoidMouse = function(distance, speed, accel){
	var xdiff = this._parent._xmouse - this._x;
	var ydiff = this._parent._ymouse - this._y;
	var dist = Math.sqrt(xdiff*xdiff + ydiff*ydiff);
	if (dist < distance){
		var angle = Math.atan2(ydiff, xdiff);
		if (accel) speed = Math.min(speed, accel*distance/dist);
		this._x -= Math.cos(angle)*speed;
		this._y -= Math.sin(angle)*speed;
	}
}

// usage:
myMovieClip.onEnterFrame = function(){
	this.avoidMouse(100, 10, 5);
}

accel is optional. If accel is used, speed defaults as the top speed. Otherwise, without accel, the speed of the clip is constant as it avoids the mouse until it reaches >= distance.

did you make it senocular?
:slight_smile:

yeah :slight_smile:

did you make that just now, or you already have done this in a previous experiment?

sorry for asking, but this is a nice piece of code you got there, and doing that in that little time baffles me :!:

I did it just now. Ive used it before a year or two ago but its hidden away in some file somewhere lost on my hard drive. It was easier to re-write it just now. I doubt its exactly the same thing I used before, but its the same concept none the less.

:wink:

Yeah… we won’t let them know who forwarded you that code just a few minutes ago…

we’ll keep that OUR little secret. If you want them to think that YOU wrote it, that’s fine… we both know who did.

:wink:

::laughing:: :beam:

*Originally posted by senocular *
**I did it just now. Ive used it before a year or two ago but its hidden away in some file somewhere lost on my hard drive. It was easier to re-write it just now. I doubt its exactly the same thing I used before, but its the same concept none the less. **

congrats for you coding skills!

don´t go far, I might need your expert advice one of these days=)

thanks for the script, it is possible to enter thw widht and height of the movie?

what i´m trying to do is this, in attach is the file

thanks

thats not avoiding the mouse. Thats just repositioning on a rollover. Something to the effect of

I must say, that this site since I discouver it (last 3 days) , is the best one.

Thanks for the script

you or other guru must wright a tutorial about this.

thanks

bull

it is possible to insert one word on each rect?

:))))

here you run into some problems since all the rectangles (in this example) are all of fixed size. It depends on how exactly you plan to format your moving ‘boxes’ - whether they will all have a sort or consistency or if they will be fairly random and of differing variations such as the example you posted. Chances are, each one of those were made manually and the script added to them individually. I myself dont like that monotonous work so I try to do as little as possible (as the example I posted used only the script on that one movieclip). But for altering that example, all you would have to do is include a textfield in Symbol 1 and give it a name like avoid_txt then in the script have something like… well heck Ill just post a new one, its not much different :wink: but the point is, if you want a lot of different sizes and variety, skip the whole duplication thing and just make them manually. If you want, I can show you away to control all the movieclips within another so you wont have to add any script to any of the unique movieclips youve made - all you would have to do is throw them in a containing movieclip and put some script on that which will work the magic on all the clips within it (assuming they are all supposed to perform the same operations).

i will give a shot.

thanks