Making an object follow the other

Subscribe to Making an object follow the other 7 posts

avatar for Shadow_Craver Shadow_Craver 344 posts
Flag Post

I’m trying to make an object follow another one when it hits it. (The moving object is called “hook”)
The Hook has an animation that allows it to move towards the other object.
I tried this in the object’s actions:

onClipEvent(enterFrame){
if(_root.hook.hitTest(this)){
	this._x=_root.hook._x
	this._y=_root.hook._y
}
}

The problem here is that the object only goes to the initial location of the hook, and doesn’t change it’s position depending on the hook’s location. How do I fix this?

 
avatar for Draco18s Draco18s 6860 posts
Flag Post

I’m guessing it stops following because the hook moved too far and the two were no longer touching.

var following = false;

onClipEvent(enterFrame){
  if(_root.hook.hitTest(this)){
    following = true;
  }
  if(following) {
    this._x=_root.hook._x
    this._y=_root.hook._y
  }
}
 
avatar for Shadow_Craver Shadow_Craver 344 posts
Flag Post

It didn’t work. I think it’s because I’m not Actually changing the hook’s coordinates, im just playing an animation. I’m not sure what to do :/

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by Shadow_Craver:

It didn’t work. I think it’s because I’m not Actually changing the hook’s coordinates, im just playing an animation. I’m not sure what to do :/

Uh.

Yes, that would be exactly what’s causing it.

And you are not going to get the object to follow that hook as it animates, because Flash does not expose details on where that hook is (it’s a frame-based animation).

 
avatar for Shadow_Craver Shadow_Craver 344 posts
Flag Post

Thanks for the reply. I guess you’re right. I’m gonna have to use XY coordinates to make the hook move in complex directions. :P

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by Shadow_Craver:

Thanks for the reply. I guess you’re right. I’m gonna have to use XY coordinates to make the hook move in complex directions. :P

Yes.

 
avatar for AldenRogers AldenRogers 275 posts
Flag Post

You may be able to place a tiny box movieclip inside the hook animation, then use it’s location as the anchor where you want the item to follow.