title: Restricting cursor to a radius around my Player
body: <p>I am currently working on an multiplayer shooter game. Basicly atm you play as a cube and you have your hand(red square) following the cursor ingame. </p>
  
  <p>I want to restrict the cursor movement to a perfect circle around my player sprite.</p>
  
  <p>See attached picture for clarification. </p>
  
  <p><a href="https://imgur.com/TLliade" rel="nofollow noreferrer">https://imgur.com/TLliade</a> </p>
  
  <p>Following script is attached to the "Hand" (red square).</p>
  
  <pre><code>public class Handscript : MonoBehaviour
  {
  
      void Update()
      {
          Cursor.visible = false;
  
          Vector3 a = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
          a.Set(a.x, a.y, transform.position.z);
          transform.position = Vector3.Lerp(transform.position, a, 1f);
      }
  }
  </code></pre>
  
  <p>Now I want to restrict cursor movement inside my radius that is a public transform attached to my Player prefab like this:</p>
  
  <pre><code>    //Hand radius
      public float radius;
      public Transform centerRadius;
  </code></pre>
  
  <p>I am hard stuck and new to coding overall and I could use a push in the right direction. </p>
  
  <p>Basicly the same question is asked here if I am being to unclear:
  <a href="https://answers.unity.com/questions/1439356/limit-mouse-movement-around-player.html" rel="nofollow noreferrer">https://answers.unity.com/questions/1439356/limit-mouse-movement-around-player.html</a></p>
  
  <p>EDIT: My goal in the end is to have similar hand movement as in the legendary "Madness Interactive" game, found here:
  <a href="https://www.newgrounds.com/portal/view/118826" rel="nofollow noreferrer">https://www.newgrounds.com/portal/view/118826</a></p>
  
  <p>EDIT2: It might be impossible to lock the cursor inside the radius circle. Is it possible to just have the GameObject "Hand" locked inside this radius?</p>
  
  <p>EDIT3: This is the code I use and it works like a charm:</p>
  
  <pre><code>using System;
  using UnityEngine;
  
  public class Handscript : Photon.MonoBehaviour
  {
      [SerializeField] private GameObject Player2;        //Drag your player game object here for its position
      [SerializeField] private float radius;              //Set radius here
  
      public new PhotonView photonView;                   //Never mind this if its not a photon project
  
      private void Start()
      {
          Cursor.visible = false;
      }
  
      void Update()
      {
              if (photonView.isMine)      //Never mind this if statement if it isnt a photon project
              {
                  Vector3 cursorPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
                  Vector3 playerPos = Player2.transform.position;
  
                  Vector3 playerToCursor = cursorPos - playerPos;
                  Vector3 dir = playerToCursor.normalized;
                  Vector3 cursorVector = dir * radius;
  
                  if (playerToCursor.magnitude &lt; cursorVector.magnitude) // detect if mouse is in inner radius
                      cursorVector = playerToCursor;
  
                  transform.position = playerPos + cursorVector;
  
              }
      }
  
  
  
  
  #if UNITY_EDITOR
      private void OnDrawGizmosSelected()
      {
          UnityEditor.Handles.DrawWireDisc(transform.parent.position, Vector3.back, radius); // draw radius
      }
  #endif
  }
  
  </code></pre>