Moving Circle Object Around an Arc Using Mouse

I am currently trying to use the mouse component as both a response and to move a circle object around an arc based on the mouse position on screen. See image below:

The word and circle I want to move about the black arc.

I know I need to use the mouse.getPos() x and y variables (I’ve tried using mouse.getPos()[0] and mouse.getPos()[1] for x and y) and then put them into equations to convert the x and y values into an angle and then convert that angle into x and y coordinates on the arc. See code below:

``````angle = Math.atan2(mouse.getPos()[1] - centerY, mouse.getPos()[0] - centerX);

arcx = centerX + radiusitem * Math.cos(angle);
arcy = centerY + radiusitem * Math.sin(angle);
``````

However, when I run this code as a component, the x and y positions are not updated by the mouse and even when I use just the mouse.getPos()[0]/[1] as the circles position to update (i.e. just have the circle freely follow the mouse) I receive a syntax error for: log=false.

Any help or suggestions?

1 Like

Resolved my own issue! For anyone in the future:

1. Create a Mouse Component
2. Create an Object
3. Set the Objects x and y position values to some variables (say x = rx and y = ry)
4. Make a code component.
5. In Begin Experiment:

import math

1. In Begin Routine

rx = 0
ry = 0

1. In Each Frame

angle = math.atan2(mouse.getPos()[1], mouse.getPos()[0])
rx = .4 * math.cos(angle)
ry = .4 * math.sin(angle)