How can I set up a 2D circular boundary in Unity?

I wanted to create a virtual analogue stick on Unity. enter image description here

I figured a very simple, 2 part method setting up a tether to the middle of a doughnut-container and a boundary would work. While the tether was quickly solved just by using Vector2.MoveTowards, the boundaries would be much harder to solve.

I initially tried to create a 2D circle collider around the doughnut-container but I didn’t know how to reverse its collisions to keep the cursor inside. Later, I tried to set up a square shaped boundary by setting up the limits of the x and y coordinates the cursor cannot exceed (these limits were also made according to the doughnut-container). Thus was done with multiple if statements:

 if (currentPoint.y >= 2.7f){currentPoint.y = 2.7f;}  if (currentPoint.x >= 2.5f){currentPoint.x = 2.5f;}  if (currentPoint.y <= -2.7f){currentPoint.y = -2.7f;}  if (currentPoint.x <= -2.5f){currentPoint.x = -2.5f;} 

However, when testing the code out, the cursor still exceeded the boundaries given:

enter image description here

Minimum reproducible code for the cursor:

public class menuScript : MonoBehaviour {     public float speed;     public Vector2 originPoint;     private Vector2 currentPoint;     // Start is called before the first frame update     void Start()     {         Vector2 originPoint = transform.position;     }      // Update is called once per frame     void Update()     {         currentPoint = transform.position;         float step = 50 * Time.deltaTime;         float vertical = Input.GetAxis("Vertical") * Time.deltaTime * speed;         float horizontal = Input.GetAxis("Horizontal") * Time.deltaTime * speed;          if (horizontal != 0 || vertical != 0)         {         transform.Translate(horizontal, vertical, 0);         if (currentPoint.y >= 2.7f){currentPoint.y = 2.7f;}         if (currentPoint.x >= 2.5f){currentPoint.x = 2.5f;}         if (currentPoint.y <= -2.7f){currentPoint.y = -2.7f;}         if (currentPoint.x <= -2.5f){currentPoint.x = -2.5f;}         }         else         {             transform.position = Vector2.MoveTowards(transform.position, originPoint, step);         }              } } 

Circular movement in 5th edition d&d

This came up in a discussion in my group about circular movement.

Do we treat this as moving diagonally or difficult terrain?

For a situation such as circling a target on a horse shooting arrows at it we fell should be treated as difficult terrain

One situation was mentioned was what if a ranger casts spike growth which has a 20 foot radius wants to completely walk around it. How long would it take? The circumference is about 125 feet and ranger base speed is 30

This came up as we wanted to know if we cast spike growth catch someone in the area of effect. If they try to move out from it and away from us can we circle around faster then they can move through it

Running through it counts as difficult terrain but what about running around it?

Linear Partition problem (Dynamic Programming) in a circular array

I am practicing algorithms for the last couple of days and I came across this question, the gist of which is:

Given apples and oranges arranged in a circle indexed form 1 to n , where n is an odd number(we know which ones apple and which ones orange), divide these into k contiguous groups each havind odd number of fruits such that most of the groups have more apples than oranges. Also, the arrangement can be such that a group can contain fruits of indices (n-3, n-2, n-1, n, 1 , 2, 3).

This appears like the linear partition problem to me, but the circular arrangement confuses me. Also, I was thinking of masking Apples as 1 and Oranges as -1 so that it’s easy to calculate the which one is higher in the group( if sum is +ve, then apples are higher else oranges). Also, I observed that k must be an odd number as n is an odd and each of the k groups have odd fruits, so sum of odd number of odds is an odd number.

We have to maximize the sum of each of the groups in this case right?

It would be great if someone can help out.

Thanks a lot!!!

Walk around a coordinate in circular order to a distance of N

For my development purpose, I need to work on all the 2D coordinates (in whole number) around [0,0] from 0 to N distance. For example, with N=1, I need

N0: [0, 0] N1: [-1, -1] [0, -1] [1, -1] [1, 0] [1, 1] [0, 1] [-1, 1] [-1, 0] 

The order is important. I want to walk these values in a circular way, starting from 0, incrementing the distance each round.

I first created two for-loops, from -N to N on each axes, but the resulting order is the one as you read a book: from top left to bottom right.

Here’s the order I aim (the first coordinate to walk on each circle is not important):

walking order

Here’s a first algorithm I tried, in pseudo code

int totalSize = (2*N+1, 2)*(2*N+1, 2) Vector2[] coordinates = new Vector2[totalSize] int index = 0 coordinates[index++] = new Vector2(0, 0) for (int d = 1; d <= N; d++) {     for (int x = -d; x <= d; x++) {         coordinates[index++] = new Vector2(x, -d)         coordinates[index++] = new Vector2(x, d)     }     for (int y = -d+1; y <= d-1; y++) {         coordinates[index++] = new Vector2(-d, y)         coordinates[index++] = new Vector2(d, y)     } } for (int i=0; i<coordinates.Length; i++) {     print(coordinates[i]) } 


  • It seems too cumbersome. I don’t like the creation of a scructure that retains the coordinates. And 4 for-loops seems not optimized.

  • The order of the circles is ok, but the order inside each circle is not the one I described.

  • I have the feeling trigonometry can help me, but I can’t see how to implement it on discrete values

Any idea?

How To Merge Together Two Circular Doubly-Linked Lists In O(1) Time?

I’m implementing a Fibonacci Heap, where the lists are stored as a circular doubly-linked lists. What I’m trying to do is given a pointer to a random node in one linked list, and a random node in another, I want to merge them together in O(1) time. I tried drawing this out, but I couldn’t seem to figure out how to do this. Here is my first idea, in pseudocode:

union(Node one, Node two) {     if other = nil         return      p1 = one     p2 = one.right     p3 = two     p4 = two.right      p1.right = p4     p4.left = p1     p2.right = p3     p3.left = p2 } 

Each Node has a left and right attribute, which stores the node to the left and right, respectively. However, this didn’t work. Can anyone figure out how to merge together two linked lists?

Why are Progressive Web App Icons circular compared to their App counterparts

Working on a PWA (progressive web app) and coming up with the app icon for it. There aren’t many others around since it’s pretty new but it seems a lot of PWAs use a circular icon to differentiate from the native app.

Is there a particular reason they are choosing a circular icon compared to the many other options? Is this a standard or a guideline(coming from google it wouldn’t be a surprise)?

enter image description here

How to resolve TypeError: Converting circular structure to JSON when creating SP list item?

Trying to create a list item in SharePoint using REST, getting the following error message:

Uncaught TypeError: Converting circular structure to JSON

Am I missing something obvious here?

$  .ajax({         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists('" + myList + "')/items",         type: "POST",         headers: {             "accept": "application/json;odata=verbose",             "content-type": "application/json;odata=verbose",             "X-RequestDigest": $  ("#__REQUESTDIGEST").val()         },         data: JSON.stringify({             'Title': 'testing',             '__metadata': { 'type': 'SP.Data.List_x005f_TasksListItem' }         }),         success: function (data) {             TX = data.d.Id;         },         error: function (error) {             alert(JSON.stringify(error));         }     });