Skip to main content
Participating Frequently
August 5, 2013
Question

Two Objects Following Each Other While Maintaining Minimum Distance

  • August 5, 2013
  • 1 reply
  • 574 views

Hello,

I'm trying to solve a problem where I have one circle following another ( the first following the mouse ), yet maintain a minimum distance between the two circles.

The code is pretty simple. For the lead circle I'm moving it as follows on the movement of the mouse:

circle.x = event.stageX + 8.000000E-001 * ( circle.x - event.stageX );

circle.y = event.stageY + 8.000000E-001 * ( circle.y - event.stageY );

Then I'm moving the secondary circle as:

circle2.x = circle.x + 8.000000E-001 * ( circle2.x - circle.x );

circle2.y = circle.y + 8.000000E-001 * ( circle2.y - circle.y );

This works remarkably well, however, I want to be able to increase the distance between the two circles and enforce a minimum. If anyone can point me in the right direction I'd appreciate the assistance. Thanks.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 5, 2013

increase .008 to increase the distance and use if-statements to enforce a minimum.

brixelAuthor
Participating Frequently
August 6, 2013

Thanks for responding. To what are you referencing that I increase by .008, not following? Thanks.

kglad
Community Expert
Community Expert
August 6, 2013

that was supposed to be .8