Wednesday, June 22, 2022
HomeGame Developmentunity - Visible Joystick shifting sooner than my finger. why?

unity – Visible Joystick shifting sooner than my finger. why?


To start with, right here‘s the video of what my downside actually is. (Sorry for unhealthy high quality)

As you may see, the pink circle is the middle of the visible joystick. The inexperienced one signifies my finger and the white circle is the deal with of my joystick.

As you may see it really works however the deal with goes sooner than my finger, I do not know why this occurs

Here is the code for setting the deal with’s place:

            RawDirection = Enter.GetTouch(CurrentFingerID).place -
                (Vector2)BGRect.place;

            if (RawDirection.magnitude > BGRect.sizeDelta.x / 2)
                RawDirection = RawDirection.normalized * BGRect.sizeDelta.x / 2;

            HandleRect.anchoredPosition = RawDirection;

that means of the variables:

  • CurrentFingerID is used to avoid wasting which finger is on the joystick presently.
  • BGRect is the RectTransform connected to the BG (see the pic beneath)
  • HandleRect is the RectTransform connected to the Deal with (see the pic beneath)

And these are BG and Deal with:

BG and Handle

I feel RawDirection must be divided by some quantity to repair this problem. Any assistance is appreciated and be happy to ask for additional information

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments