Public Group

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.

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.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 17
• 18
• 12
• 14
• 9
• Forum Statistics

• Total Topics
633362
• Total Posts
3011528
• Who's Online (See full list)

There are no registered users currently online

×