Quick Question about Rotation

I know this might be a dum question…
:face_with_monocle:

But how do make an arrow continuously rotate towards a moving object, or a mouse?
:point_right: :point_left:
:arrow_up: :arrow_upper_right: :arrow_right: :arrow_lower_right: :arrow_down: :arrow_lower_left: :arrow_left:

Hi @Hamzah_Alani!

Here’s a project with an arrow pointing to the mouse:
PointToMouse5-18-2020_10-23-42AM.wick (2.2 KB)

I used the Math.atan2(y, x) function which calculates the rotation angle from the difference in location (the arctangent). atan2 gives the answer in radians but Wick uses degrees, so I multiplied it by 180 / pi to convert. Here’s the important line of code:

this.rotation = -Math.atan2(this.x - mouseX, this.y - mouseY) * 180 / Math.PI;

Let me know if you have any questions!

1 Like

Thanks @nick this is exactly what I needed!
:smile:

I was trying to do the exact same thing, but my trig is trash. if it weren’t for me giving up I would have spent like half an hour doing something that someone already did. :grin:

:mask: stay safe y’all

1 Like