ActionScript 3: MovieClip not following cursor
I'm working on testing an interactive animation where a spider follows my cursor with a delay and a fly follows my cursor much more closely, to give the illusion that the spider is chasing the fly. However, when I test the animation the spider moves as it should, but the fly stays at a radius far from the cursor without approaching it. I don't know much about coding, but the code I have for the spider and the fly is the same, so I'm not sure why only the spider is acting correctly. Here's the code I'm using:
this.addEventListener(Event.ENTER_FRAME, MoveSpider);
function MoveSpider(evt:Event):void
{
var xMouse = root.stage.mouseX;
var yMouse = root.stage.mouseY;
if(Math.abs(xMouse - Spider.x) < 1)
{
//if spider is within 1px move to mouse position
Spider.x = xMouse;
Spider.y = yMouse;
}
else
{
//move spider 1/6 of the way to mouse each frame
Spider.x -= (Spider.x-xMouse) / 100;
Spider.y -= (Spider.y-yMouse) / 100;
}
}
this.addEventListener(Event.ENTER_FRAME, MoveFly);
function MoveFly(evt:Event):void
{
var xMouse = root.stage.mouseX;
var yMouse = root.stage.mouseY;
if(Math.abs(xMouse - Fly1.x) < 1)
{
//if fly is within 1px move to mouse position
Fly1.x = xMouse;
Fly1.y = yMouse;
}
else
{
//move fly 1/6 of the way to mouse each frame
Fly1.x -= (Fly1.x-xMouse) / 100;
Fly1.y -= (Fly1.y-yMouse) / 100;
}
}
If anyone knows why my fly wants to social distance I'd be grateful for any help!
