Page 1 of 1

Moving objects with incremental slowdown..

Posted: Thu Apr 16, 2020 12:44 pm
by exxos
Moving a object to the right for example I can simply do X=X+1 kinda thing. But there are effects where the object moves really fast for maybe 80% like X=X+10, but then incrementally slows down to a stop.

There is also another effect which has a kind of "rubber bounce" at the end, where it overshoots the stop position slows down and moved back to the left a few pixels. I guess the demo coders may know of this effect and how possibly to do it?

I am sure I did this in STOS like 25 years ago.. and it was using SIN/COS in the mix to get the full effect.. But I don't remember anything about it now :( I guess as a last resort I could just manually type in a table of numbers to do the effect.

Re: Moving objects with incremental slowdown..

Posted: Thu Apr 16, 2020 12:49 pm
by PhilC
Table of numbers is how I used to do my sine scrollers etc.

Re: Moving objects with incremental slowdown..

Posted: Fri Apr 17, 2020 7:40 am
by mikro
Yup, just use a 1D array of some nice function (can be sin, cos, log, whatever you prefer/looks nice but sin is probably the easiest way).

So the first effect is easy, start at sin(90) = 1 and decrement the angle (index) to 0 (or increment to 180, same thing) which will produce smaller numbers (increases to X in your case). Of course, it's much easier to precalculate the whole thing, i.e. have the final "X" in your table for each increment.

For the bounce effect, that's easy, just don't end up with sin(0) directly on the border but, with, say, sin(5) so the last indices (4, 3, 2, 1, 0) would fall behind the border. Then wrap your sine curve and start counting backwards the same amount (5 indices in my example), putting it back to the border.