ActionScript 3: MovieClip not following cursor

Community Beginner ,
Oct 25, 2020 Oct 25, 2020

Copy link to clipboard

Copied

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!

TOPICS
ActionScript, Code

Views

77

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Community Beginner , Oct 25, 2020 Oct 25, 2020
Idk how to delete this, but the fly MovieClip wasn't centered on the stage. That's all it was. I am dumb.

Likes

Translate

Translate
Community Beginner ,
Oct 25, 2020 Oct 25, 2020

Copy link to clipboard

Copied

Idk how to delete this, but the fly MovieClip wasn't centered on the stage. That's all it was. I am dumb.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

LATEST

Hi.

 

You're not dumb. Programming is often tricky.

 

I will mark your answer as correct in case someone comes across the same situation as yours.

 

Regards,

JC

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines