How to point toward given position (javascript) when knowing current position

This will be necessary for my Space Chaos game, since, there is nothing called POINT TOWARD MOUSE POINTER in javascript.
I have to manually do it.
How do I calculate the angle of the hypotenuse, given 2 points? Remember this needs to work with the javascript canvas coordinate system

is this for a javascript project of yours? if so, the help with snap! isn't a good category for this.

but anyway do this will probably work

Math.atan2(mouseY - y, mouseX - x);

Please make it degrees I have problem with radians

Math.atan2(mouseY - y, mouseX - x) / Math.PI * 180

how do i check your answer
like :heavy_check_mark: check

click the solve button

wait hold on

i think you click summarize topic or something

you press "solution" on pumpkinhead's post

This thread was flagged as offtopic (because JS) but I allowed it because really it poses a math question rather than a programming question. The same answer works in Snap!:

But in Snap! it's Δx/Δy instead of Δy/Δx because we measure angles clockwise from North instead of ccw from East.

There is no solution button

People no like js nor math nowadays

Only some categories have solution buttons. "Help with" categories lend themselves to solutions, but discussion categories, including this one, are more open-ended.

I can't decide whether to be pitying or angry about this. You asked a math question. You knew you were asking a math question, because you posted it in a category named "Math"! But now you seem to be saying "I don't care to understand this; I just want someone to write the code for me." Pfui.

first, move the category to help with snap!/snap editor, click solution on pumpkinhead's post, then move this topic back to computer science/math.

Wait will that actually work?

Yep @sathvikrias big brain

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.