0
\$\begingroup\$

I am creating a minigame that involves rotating colored circles so that the colors match relative to the central circle which is fixed. I was thinking of checking with colliders that the two points at the beginning of one color and the end match with some tolerance to the other circle which also has such collider points set, but I don't know if this is a good solution. Attached Graphics are only for placeholder purposes and not to scale.

Current rotate script:


   public class RotateCircleMinigame: MonoBehaviour
   {
    
       private Vector3 screenPos;
       private float angleOffset;
    
       void Update()
       {
           Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
           if (Input.GetMouseButtonDown(0))
           {
               screenPos = Camera.main.WorldToScreenPoint(transform.position);
               Vector3 vector3 = Input.mousePosition - screenPos;
               angleOffset = (Mathf.Atan2(transform.right.y, transform.right.x) - Mathf.Atan2(vector3.y, vector3.x)) * Mathf.Rad2Deg;
           }
    
           if (Input.GetMouseButton(0))
           {
               Vector3 vector3 = Input.mousePosition - screenPos;
               float angle = Mathf.Atan2(vector3.y, vector3.x) * Mathf.Rad2Deg;
               transform.eulerAngles = new Vector3(0, 0, angle + angleOffset);
           }
       }
   }

Image 1 - on start rotate Image 2 - correct rotates to finish

\$\endgroup\$
8
  • \$\begingroup\$ "I don't know if this is a good solution" - well, when you try it, does it work? That's usually a sign of a good solution. It's not clear to me from reading this question what specific "problem" you need help solving. Have you encountered an obstacle in getting your idea to work, or found a bug/unwanted behaviour? Or is the code/setup process excessively onerous in some way? What can we help you fix/improve? \$\endgroup\$
    – DMGregory
    Commented Sep 14, 2022 at 12:49
  • \$\begingroup\$ I have no idea how to implement this reasonably well. \$\endgroup\$
    – Jorr1
    Commented Sep 14, 2022 at 13:11
  • \$\begingroup\$ You mentioned an idea using colliders. Do you feel that approach isn't "reasonable"? Or did you get stuck on a specific step when implementing it? \$\endgroup\$
    – DMGregory
    Commented Sep 14, 2022 at 13:26
  • \$\begingroup\$ Implementing this idea with colliders will not be a problem for me, it just makes me wonder if this is a good idea or maybe there is a better one. \$\endgroup\$
    – Jorr1
    Commented Sep 14, 2022 at 15:11
  • \$\begingroup\$ Then we're back to my first question: Step 1. Implement your collider idea. Step 2. Evaluate how well it works. If it works well enough for your goals, it's a good enough solution and you can move on to the next thing. Step 3. If the solution does not work well enough for your goals, then edit your question here to describe exactly how it falls short, then you can get answers about solving that specific problem you've identified. \$\endgroup\$
    – DMGregory
    Commented Sep 14, 2022 at 15:18

0

You must log in to answer this question.

Browse other questions tagged .