Public Group

# Should be simple, Flash actionscript

This topic is 4904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

say ive got a Red Box on the bottom left of teh screen and a Blue Circle on teh top right what do i have to do to get that Blue Circle to move slowly to the Red Box and stop about an inch away? and further more, say that Red Box was to move up for some reason, how would i have it so that Blue Cirlce will follow it up? any help would be greatly appriecated

##### Share on other sites
Not so simple. The actionscript will basically be like this.
(each frame)
get position of blue circle
get position of red square
check the distance between the blue circle and the square
if the distance is close, don't move the red square
otherwise
move red square in a direction according to the difference between the positions

##### Share on other sites
I don’t know Flash but, but a C language example would be:

X_distance = Circle_Pos_X - Box_Pos_X;Y_distance = Circle_Pos_Y - Box_Pos_Y;distance = sqrt( X_distance*X_distance + Y_distance*Y_distance); //sqrt() means Square RootVelocity = 10; // can be any number reallyif(distance > Minimum_distance){    Circle_Pos_X += (X_distance / distance) * Velocity;    Circle_Pos_Y += (Y_distance / distance) * Velocity;}

Do this each frame.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015432
×