PDA

View Full Version : need help with effect... modifying pom's tutorial



Scott
April 24th, 2002, 07:53 PM
hey... im tryin to make a mouse swarm effect... where all these little dots swarm around the mouse... im using the physics spring tutorial that pom made... and trying to modify the code so if the distance between the object and the mouse is less than a given value, the inirtia is changed to 1 so it will constantly move... i tried doing that with an if statement cuz thats the only way i can think of doin it... but it doesnt work... um... and secondly, when that gets workin, i want the inirtia to get to a set speed so it wont be shooting off the screen or anything without slowing down... should i set that manually or what... or will it just slow down by itself when it shoots out of the distance range?... anyway heres the code that i modified

in object:
onClipEvent (enterFrame) {
this.move(_root._xmouse, _root._ymouse, 0.95, 0.1);
}

in actions frame:

MovieClip.prototype.move = function (centerx, centery, inertia, k)
{
x = -this._x+centerx;
y = -this._y+centery;

if(x > 100 or y > 100){
inirtia = 1;};

xp = xp*inertia+x*k;
yp = yp*inertia+y*k;
_x += xp;
_y += yp;
};

i can email an example my friend made... (he wont tell me how to make it though... thats why im commin to u guys)

thanks...

-scott

sinfiniti
April 24th, 2002, 10:25 PM
onClipEvent (enterFrame) {
nHypot = Math.sqrt((_xmouse*_xmouse)+(_ymouse*_ymouse));
nXmov += _xmouse*0.2;
nYmov += _ymouse*0.2;
if (nHypot>50) {
nXmov *= 0.75;
nYmov *= 0.75;
}
_x += nXmov;
_y += nYmov;
}

just replace '0.75' with the desired friction, and '0.2' with the desired acceleration. '50' is the distance (in pixels) at which friction stops.
:)
jeremy

ilyaslamasse
April 25th, 2002, 05:29 AM
You're too fast, Sinf...

pom 0]

ilyaslamasse
April 25th, 2002, 05:32 AM
As a matter of fact, I didn't understand what you were trying to do, Scott, so thanks twice, Sinf.
Can you post that example anyway ??

pom 0]

scootman169
April 25th, 2002, 10:02 AM
its pretty much what i wanted... my friends is a little diffrent.. .like smoother movement... ill put it on a site or somthin tonight... or ill email it to you pom... i dont know maybe i just gotta mess with the values more... or somthin...
thanks again
-scott