- Home /
How to get an object to move your camera while being confined to a circle
I'm making a bullet hell game and I want the reticle to be confined to a circle which I have done but the cursor wraps around the circle it can't move inside of it it just traces it's shape. Here's what I have so far:
Vector3 center = FindObjectOfType().GetComponent().position; cursorPos = -transform.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, transform.position.z)); Vector2 diff = Input.mousePosition - center; float distance = diff.magnitude; if (distance > 5) { cursor.transform.position = new Vector2(center.x, center.y) + (diff / distance) * 5; } else { cursor.transform.position = new Vector2(cursorPos.x, cursorPos.y); }
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to get the colliders working? 1 Answer
Help With C# Debug 2 Answers
How to use #define to turn debug information on/off 1 Answer