I'm trying to make it so that a triangle, with its two base points always staying on the outer edge of a circle, will point towards where the mouse is. I'm convinced it's mostly a specific math problem I'm missing, but I haven't been able to figure it out. To reiterate, I'm trying to make something kind of like those .io games, where the player appears as a circle, and an arrow comes off the circle always pointing the direction the mouse is.
Since scratch uses a three-point system for drawing triangles, I've been trying to find a formula that will use the circle's circumference and the variables mouseX and mouseY to find the bottom two points for the triangle, no matter where the mouse is on the screen. Because of this I've been using this formula:
mouseXRelative = mouseY-(mouseX-(x+25));
mouseYRelative = mouseX-(mouseY-(y+25));
cEdgeXL = x + 25 * cos(mouseXRelative*radians(1));
cEdgeYL = y + 25 * sin(mouseYRelative*radians(1));
cEdgeXR = x - 25 * cos(mouseXRelative*radians(1));
cEdgeYR = y - 25 * sin(mouseYRelative*radians(1));
stroke(0,0,0);
triangle(cEdgeXL,cEdgeYL,mouseX,mouseY,cEdgeXR,cEdgeYR);
MouseXRelative and mouseYRelative are meant to hold the distance relative to the endpoint of the triangle.
I've gotten it pretty close to what I want, but the main bug I've come to find is that the points will almost spin around the edge of the circle? It looks really weird.
Are you over-engineering it?
If you draw that triangle on the "circle" sprite, you could just instruct it to point to the mouse.
See my demo on Scratch.
Here is an example of the sprite's costume:
And here is the code that rotates the sprite: