Answer the question
In order to leave comments, you need to log in
Object following the cursor?
Hello.
I need to move a single object, which I select by clicking, behind the mouse cursor. Now he is moving back and forth and up and down, I still need to do it left and right, but something doesn’t work out for me (((
Help, please
Answer the question
In order to leave comments, you need to log in
Hang on the mouse movement handler the calculation of the angle between the mouse coordinates and, for example, the center of your object, remember this angle.
Further, at each iteration, we move to the object in this direction with the desired speed of the type
var speed = 10*deltaTime;
objx += Math.cos(angle) * speed;
objy += Math.sin(angle) * speed;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question