So I’ve been working on a script that uses Vector2.ClamMagnitude to keep an aiming reticle within a certain area. I’m look for an efficient way to also have a minimum radius or a way to lock the reticle on the maximum radius. This is the code I’ve got:
public class Weapons : MonoBehaviour {
public GameObject playerObject;
public Transform cursor;
public float radius;
private Vector2 mousePos;
private Vector2 centerPoint;
void Update()
{
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
centerPoint = playerObject.transform.position;
if (Input.GetMouseButton(1))
{
cursor.GetComponent<SpriteRenderer>().enabled = true;
Vector2 newPos = mousePos;
Vector2 offset = newPos - centerPoint;
cursor.position = centerPoint + Vector2.ClampMagnitude(offset, radius);
}
else
{
cursor.GetComponent<SpriteRenderer>().enabled = false;
}
}
}
So yea the reticle is currently able to move freely within the boundaries of the radius but I’d like to find a way to either force it to stay at the edge or have a minimum radius feature. How should I go about achieving this? ![]()