Advertisement Jump to content
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
Share on other sites
Guest Anonymous Poster
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
move red square in a direction according to the difference between the positions

Share this post

Link to post
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 Root
Velocity = 10; // can be any number really

if(distance > Minimum_distance)
Circle_Pos_X += (X_distance / distance) * Velocity;
Circle_Pos_Y += (Y_distance / distance) * Velocity;

Do this each frame.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!