0

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);
});
Eric T
  • 944
  • 1
  • 11
  • 26

1 Answers1

0

If I'm understanding your question correctly, you want to drag a particle/circle/rectangle from an origin and then on touchend have the particle/circle/rectangle move back to the origin.

One of the ways to accomplish this withe the physics engine is through a Spring. If you look at the Scrollview, internally it uses a spring to "bounce" back when you reach an edge. I'll see if I can work up a quick implementation later to demonstrate this.

Joseph Carroll
  • 465
  • 6
  • 15
  • I've figured out a solution - might not be best practice, but I'll update my question with it now. – Eric T Apr 03 '15 at 16:48
  • `Spring` is probably a better solution here - thanks for pointing it out. I'll try to work something out with it, but if you come up with something in the meantime please let me know. Thanks! – Eric T Apr 03 '15 at 16:56