edit don't know what I was thinking when I added the thread title, but this doesn't have anything to do with AS3...
AS2 - THROW / FRICTION / SNAP
I'm stuck trying to achieve something in AS2. The principle is easy: the user can drag/throw a timeline (with thumbnails) around, but I want it to snap to certain positions. I've created an example to show what I need:
HOT XXX THROW FRICTION SNAP PORN
You can already drag/throw the timeline around, but, as it slows down, I want it to always snap into a position where one of the purple rectangles snaps to the grey area so a thumbnail is always covering the grey area.
So when you throw the timeline hard enough, it would fly quite far (speed of timeline > attraction force of the snapping points), but as it slows down, the snapping force takes over and the timeline snaps in place.
I'm pretty clueless here so any help or direction would be greatly appreciated!
I presume you have a variable in there to track the speed it's going once it's been thrown?
Well then, every frame check that speed:
if speed < min_speed then if in correct position to stop then speed = 0 else // no need to do anything, let it carry on at the same speed end if else apply friction end if
min_speed could be something like 3/4 px per frame. You'll play with the number until it looks right.
Or maybe you could detect when it's below the min speed, then work out which purple square is closest to the stop position and apply a tween to the speed variable with a bounce effect to make it snap into position with a bounce?
Without trying these out it's hard to imagine which will give the nicest looking results.
Thanks for looking at it. The thing you propose might work, and I'll definately keep that idea for when I don't find the right solution to the problem, but ideally the slider would behave a little different.
I can best compare it to e.g. a spinning wheel of fortune. At first, the wheel spins very hard, and when it slows down, the speed will start to 'wobble' as the wheel gets slowed down by the force of the needle. Once the force the needle applies to the wheel is bigger than the force of the spinning wheel, the wheel comes to a stop.
So theoretically the snapping points should attract the slider, but only a little bit so the attraction is only noticable when the speed is very low.
ok so check every frame if a block is over the stop area (or within a few pixels of it) and reduce the speed by a few pixels per frame. Check that the speed hasn't dropped below zero or is at zero - if it has then set it to zero and make sure the block is properly on the stop area.
I got it!!!
This is how I got it working: every frame, I check which block is the closest to my snapping point. I calculate the distance to it and add this to my speed:
dist = cntnr.timeline._x -(Math.round(cntnr.timeline._x/130)*130); Math.abs(speed) > 20 ? friction = .85 : friction=.5 cntnr.timeline._x -= speed; speed=speed*friction; speed+= (dist/10)
From the moment my speed is low enough, I change the friction of the movement (to prevent too much bouncing).
Thanks DontBogartme for your help!
nice one, it's looking good :thumbsup:
looks good.
Another approach (which would remove the need to do the final adjustment) would be to calculate the distance (not the velocity) as a factor of the throw then use Tweener to animate to that final position. The only gotcha would be that the tween time would also have to be a factor of the distance thrown.
it's done!!! HOT XXX STOPMOTION PORN
what an awesome project Flux
You should throw this out to the 12S masses...
Just one thing, in case you want to know, in the How Does This Work panel - the text WATCH THE MOVIE doesn't fit into the button
.... oh, you did 
yes... I did, and the button label should be fixed. Thanks for pointing that out!