Jump to content
  • Advertisement
Sign in to follow this  
Kid4Today

Should be simple, Flash actionscript

This topic is 4842 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
Advertisement
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
otherwise
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!