- Home /
The question is answered, right answer was accepted
How to get smooth analog joystick rotation without "snapping"?
So, my basic problem is this: I can't seem to make Unity detect small deviations in joystick movement around the north, south, east and west corners.
To elaborate: I have a simple bit of code in place to rotate my top-down 2D character using the right analog stick of a gamepad:
float angle = Mathf.Atan2(Input.GetAxis("Joy1 Horizontal"), Input.GetAxis("Joy1 Vertical")) * Mathf.Rad2Deg;
myObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
However, I noticed that when I move the joystick's angle anywhere close to the north, south, east or west directions, the character would "snap" to that direction. For example, if I point directly north so that my horizontal and vertical output is 0,1, and then move the joystick slightly to the east or west, my output remains at 0,1 for a few degrees. I would like for ANY small amount of joystick movement to be detected, to create a smoother feel for the player.
Currently, I have the sensitivity for my two axes set to 1, and my dead zone set to 0.001 (which is probably way too low), though I've played around with these values extensively to no avail. There is no problem with the physical joystick itself-- the snapping I've mentioned does not occur in certain similar games that I've tested.
Any ideas? It seems like this must be a common issue for anyone doing a game that relies on joystick aiming.
Answer by Doghelmer · Mar 20, 2015 at 07:26 AM
Upon doing some more research, I found a good solution here:
I have used the best way as described here and it still keeps snapping. I tried to do it at least 10 different ways, they all result in the same snapping. If you know the solution by now, please share.
Thank you
Answer by Guy_Yome · Apr 04, 2016 at 04:11 AM
I know this post is old, but I programmed a good solution that fixes the precision problem on the analog joystick. The problem on those is that the sensitivity range is not in a circle but in a square. I did not find a solution online so I made myself one that smoothly converts a square analog to a circle analog.
If you still wanna see it, just tell me. ( I need to translate the code if I wanna show it to you ).
Hi, I know it's been like 3 years, but I'd really like to know how you went about avoiding deadzone snapping. It has been burning my brain for the past 3 days. Godspeed.
Follow this Question
Related Questions
Joystick movement conversion to angle doesn't work anymore in C# 1 Answer
Rotate Locally Player Towards Joystick/Axis Input 1 Answer
Getting ScrollWheel/Joystick Direction w/ InputSystem 0 Answers
Rotation of a object depending on where the joystick is facing 1 Answer
Keyboard/Joystick Inputs Do Not Work until Mouse Clicked 0 Answers