PDA

View Full Version : [AS1] Movement, still unfinished


marcelozep
06-21-2009, 04:16 AM
Hello.
I have a black square in the middle of the stage named "m".
This black square moves right and left, up and down, with a changeable speed, like, increasing speed ->acceleration, and decreasing speed -> deceleration.
The problem is:

How to do this movieclip goes easying when it reachs the right limit -50 (by the Flash coordenates, right more x, left less x), or the left limit + 50?
I mean, for example:

Imagine if you have a stage size with the properties 800x600, so you have 800 of width.
If the movieclip ("m"), goes right and it passes the 750 x point, the movieclip should go easying (decreasing) the speed gradually untill speed reachs 0, and the movieclip reachs on the edge of the stage. That is, the 800 x point, minus the movieclip width divided by 2 if the movieclip named "m" are with the registration point exactly in its middle, or just its width if you are using Flash 8 or higher.
Remember, the movieclip should return to middle and do the exactly same movement when going the right or left limits again.

Thanks :)

rrh
06-22-2009, 02:08 AM
You mean if M always decelerates at a speed so it reaches Xspeed 0 at Xposition 800 no matter what speed it was at when it reached Xposition 750? Like, it could have an Xspeed of 20 or 10 or 5 and it will always reach Xspeed of 0 at Xposition 800?

Assuming that, plus assuming linear acceleration:
Distance is 50, starting speed is Xspeed, goal speed is 0. Average speed will be Xspeed/2. The Time taken to travel Distance is 50/AverageSpeed. The Deceleration needed to reach a Speed of 0 in that time is Xspeed/Time.

So, mash that all together:
decel = -Xspeed/Time;
decel = -Xspeed/(50/AverageSpeed);
decel = -Xspeed/(50/(Xspeed/2));

So I guess when you cross the threshold of 750, assign the value to decel accordingly.