Animating an object from one position to other

Hello there,

I would really appreciated some help with this question that I’m stuck on. im trying to get an object to move from one position (last mouse click) to a new position (most recent mouse click).
I’m familiar with functions like: “mouseClicked, pmouseX, mouseX”. so it would be helpful if anyone can use those functions to give me an example of how I can animate an object like ellipse at a certain speed from one position to another.
Thanks in advance :slight_smile:

Shameless self-promotion: here is a guide on animation in Processing:

1 Like

do you know how I can make the ball follow to where I click my mouse inside of the “gravity”. sorry im new and unfamiliar with the concept of mouseClicked.

You’d probably want to store the clicked position in a set of variables, and use those variables to update your position each frame.

Start with something simpler. Can you create a small example sketch that moves a circle from one hard-coded position to another hard-coded position? Get that working before trying to move it to the mouse position.

yes I have got that working, the object appears wherever I click my mouse. but I’m unable to make it smoothly transfer there at a constant speed.

Were you able to resolve this issue?

Normally, for a smooth transition, I would use PVector.lerp().

But you said “at a constant speed” – so I would just use a PVector and subtract a standard amount from the distance to the target, so long as target distance is farther away than the speed.

However, there are many was to solve this problem!

1 Like