Answer the question
In order to leave comments, you need to log in
How to make an object smoothly catch up with the mouse?
That is, with sudden movements, the object should smoothly accelerate and then slow down when approaching the mouse. The position of the mouse can constantly change, so we only know the position of the object and the coordinates of the mouse at a particular moment in time, in the next frame the data may be different.
Answer the question
In order to leave comments, you need to log in
On the mousemove event, add the mouse coordinates to the queue
On requestAnimationFrame, pull out several elements from the queue, and the larger the queue, the more we pull (you need to select), adjust the velocity vector according to the received set of coordinates and draw the movement
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question