Answer the question
In order to leave comments, you need to log in
How to implement the movement of the player behind the mouse cursor?
Prompt in what direction to think.
I do not know how to implement the movement of the player behind the mouse cursor
The game is written using Canvas in JS, the size of the playing field is 100 * 100 cells of the array that contains objects.
A screen of 20 * 20 objects is unloaded to the player.
When moving up, down, right, left, I simply load a piece of the map relative to the starting point
. Thus, the player is always in the center of the screen, and the map moves.
But you need a control in which the player moves behind the mouse pointer, the speed is constant, when the pointer is hovered over the player, there is no movement.
I catch the position of the mouse inside the Canvas through onmousemove and the values layerX, layerY
As I understand it, it is necessary to calculate the angle relative to the position of the mouse and the center of the canvas block, but I won’t know what to do with it longer
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question