Answer the question
In order to leave comments, you need to log in
How can you create a vector from the main object?
Hello everyone, I have this thread:
How it is possible to start up a vector from the main object which chases the cursor? Or do something like a shot?
How can such a thing be implemented? How can you calculate the degree relative to an object?
I would be grateful for any input.
Thanks
Answer the question
In order to leave comments, you need to log in
It’s better to do it right away and on the canvas, the angle can be obtained using the following function in radians
//Получить угол между двумя точками
function getAngle(dx, dy, dx1, dy1) {
return Math.atan2(dy - dy1, dx - dx1) + Math.PI;
}
///Получить растояние между двумя точками
function getDist(x, y, x1, y1) {
return Math.hypot(x - x1, y - y1);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question