Ok, first things first. Check out 24-7 media so y’all will see what I’m talking about.
Do you see the fly which runs away from your mouse? I’d like to come up with the same thing, but for a spider. Does anyone have any ideas how I can make this look realistic? Please help I’d really like a spider on my website.
So here’s the idea:
My spider has a global speed that is handled by the changeSpeed function. That function sets the variables targx and targy, the target destination, by checking the Mouse position and taking the opposite direction. I used setInterval to update the speed and direction every 1000 ms:
Then the legs will move around this global target destination, on a circle. They are created with the generateLegs function that duplicates the clip called ‘body’ (or nothing if it doesn’t exist). The motion is handled by the moveLegs: it takes one of the legs, feeds the destination according to the global destination and the given leg, and makes the leg ease to that destination. The reason I used legs_copy_arr is that I wanted the legs to move in sequence. Using this system, after a leg has moved, a different leg will move.
LEG_LENGTH = 40 ;
NUM_LEGS = 6 ;
legs_arr = [] ;
for (var l = 0; l < NUM_LEGS; l++) legs_arr.push(l) ;
legs_copy_arr = legs_arr.concat() ;
dot_arr = [] ;
function moveLegs () {
if (legs_copy_arr.length == 0) {
legs_copy_arr = legs_arr.concat() ;
}
var int_leg = random (legs_copy_arr.length) ;
var leg_mc = dot_arr[ legs_copy_arr[int_leg] ] ;
legs_copy_arr = legs_copy_arr.removeAt (int_leg) ;
leg_mc.targx = targx + LEG_LENGTH * Math.cos ( leg_mc.ang ) ;
leg_mc.targy = targy + LEG_LENGTH * Math.sin ( leg_mc.ang ) ;
leg_mc.onEnterFrame = function () {
var dx = this.targx - this._x ;
var dy = this.targy - this._y ;
this._x += dx / 5 ;
this._y += dy / 5 ;
if ( Math.abs(dx) + Math.abs(dy) < 1 ) {
delete this.onEnterFrame ;
}
}
}
function generateLegs () {
for ( var i = 0 ; i < NUM_LEGS ; i++ ) {
dot_arr.push ( body.duplicateMovieClip ( "d" + i, i ) ) ;
dot_arr*._xscale = dot_arr*._yscale = 50 ;
dot_arr*._visible = false ;
dot_arr*.ang = 2*Math.PI * i / NUM_LEGS ;
}
}
generateLegs () ;
setInterval ( moveLegs, 500 ) ;