I have a Circle
(which I'll refer to as Particle
throughout the question) with a Modifier
then a Surface
added to it that pipes events to a Generic Sync
(Touch/Click). The sync
events allow me to change the position of the Particle
on start
, update
and end
events so I can drag it around within a bounding box.
There's a rule in my application that if the distance between the particle's position on the sync's start
and end
events is under a certain threshold, then the particle needs to animate back to the start
position.
For example: The particle starts at [0,0] on sync start
, and is moved to [100,100]. The distance between the two points (about ~141.42) exceeds my threshold of 50...
How can I apply a force/velocity/?? to animate the Particle
back to [0,0]?
Note: I know I can do this with Modifiers
pretty easily, but I'm trying to strictly use the Physics engine.
EDIT: I figured out a solution that involves using a transitionable and setting an interval to run that constantly updates the particle's position, then setting the transitionable to my desired final position and clearing the interval in the transitionable's callback.
var retreatTrans = new Transitionable(myParticle.getPosition());
// Set a temporary interval to update the position
// as we change the transitionable (below)
var retreatInterval = setInterval(function () {
myParticle.setPosition(retreatTrans.get());
});
// Set transitionable to our desired retreatPosition
retreatTrans.set([0,0], {duration: 100}, function () {
// Clear our interval
clearInterval(retreatInterval);
});