Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Dec 25, 2018 at 03:38 PM by jimmosio for the following reason:

OP found the solution

avatar image
0
Question by jimmosio · Dec 24, 2018 at 02:47 PM · inputcontrolleraxisjoysticksnapping

Problems with joystick / controller axes being 1/-1 "way too often"

EDIT: If your controller axes "snap" to 8-directional rotations, make sure the axis sensitivity is set to a "mild" value like 1 and/or that you're using radial deadzones . Those two seem to be the main issues that make the problem rise. The reply might be useful if your joystick controls make use of the magnitude (how far from the center of the stick you move)

I'm making a 2.5d space shooter, and rather than having a "twin stick" movement I have a "thrust" button and a "turn" thumbstick: wherever you point, the ship turns that way.

I also have mouse-kb input which works well.

I have a "controller snapping" problem on my hands, where the horizontal/vertical axes only have extreme values (either -1 or 1) when the thumbstick is on the edge of its "circle".

I've tried with three pads so far: a generic Logitech, a (severely worn) 360 and a Steam Controller.

I don't know if this is what exactly is happening, but my best guess is that the axes only have the intermediate values inside a square: TopTextBottomText

Now, this is an extreme representation, but on the edge of the circle it seems very easy to be on the (1,1), (-1,1), etc. inputs compared to... anything else, really. BUT when the stick is approximately inside the square then I can rotate freely.

Just to be sure it's not a hardware/driver problem, I tried playing Beat Hazard Demo and I was able to move around as I pleased, as close to the edge as I wished.

The "Horizontal" and "Vertical" input axes that I'm using pretty much have the default parameters, and I'm using a radial deadzone, a clamping to the input magnitude and a "square to circle" transformation.

Keep in mind that this snapping problem is present with or without those things.

Is there something I don't understand about how the input axes work?

These are the hor/ver axes: axes

This is the relevant code, although I believe it has to do with the axis input itself, but might as well show it:

         //JOYSTICK INPUT
         float h = Input.GetAxisRaw("Horizontal");
         float v = Input.GetAxisRaw("Vertical");
             
         //Transform square axes into circle
         float horin = h * Mathf.Sqrt(1 - 0.5f * h * h);
         float verin = v * Mathf.Sqrt(1 - 0.5f * v * v);
 
         joyin = (new Vector3(horin, 0.0f, verin));
 
         //Joystick deadzone and clamping
         if (Mathf.Abs(joyin.magnitude) <= JoystickDeadzone)
             joyin = Vector3.zero;
         else
             joyin = Vector3.ClampMagnitude(joyin, JoystickClamp);
 
         //MOUSE INPUT
         ...

         bool UsingJoystick = (joyin != Vector3.zero);
         bool UsingMouse = ...
 
         //Mouse input: project mouse position onto game plane
         if (UsingMouse)
         {
             ...
         }
 
         //Joystick input: depending on joystick output, turn around
         if (UsingJoystick)
         {
             float r = 256.0f;
             directioninput = r * joyin;
             targetpos = transform.position + directioninput;
 
         }
 
         //Boost input
         ...
         //Thrust input
         ...
 
         //Actually move the ship
         #region
         Vector3 goalpos = transform.position + directioninput;
                     engine.MoveThing(goalpos, thrustinput, boostinput, true);



For reference, engine.MoveThing() simply thrusts and turns the ship towards the desired position.

unityaxeshlep.png (6.6 kB)
unity-2018-12-24-15-42-18.png (34.0 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vega4Life · Dec 24, 2018 at 04:28 PM 0
Share

Are you doing your testing with a keyboard? As in moving your character with left/right arrows?

avatar image jimmosio Vega4Life · Dec 24, 2018 at 06:54 PM 0
Share

I don't use arrow keys or anything similar for the mouse-kb input. I used the arrow keys in replacement for the joystick to test if the axes worked, but that was the end of it, now the hor/ver axes only take joysticks as input.

avatar image Vega4Life jimmosio · Dec 24, 2018 at 07:24 PM 0
Share

Sure. I was just making sure that if you were using $$anonymous$$B keys as testing, using GetAxisRaw will definitely only give input of -1/1. Unlike, GetAxis, would smooth out the input.

1 Reply

  • Sort: 
avatar image
1

Answer by Eno-Khaon · Dec 24, 2018 at 07:56 PM

If your intent is to clamp to a magnitude of 1 when your combined x/y inputs exceed it, then you don't really *need* to be able to provide x/y inputs both at values of 1 on a 45° angle. A 45° angle would maximize input to sqrt(2.0) /2 or ~0.707 per axis.


However, if your intent is to have two separate axes, each capable of reaching a value of 1 simultaneously, then the logical problem instead is having a circular "joystick" to provide input in the first place.

Obviously, for any physical controllers, insisting that their analog stick should have their framing circle(s) cut into a square shape would be silly.

Realistically, a meaningful alternative at this point would be mapping a square to a circle. This would result in uneven shifts in input values with certain kinds of movement, but there's also no real means of avoiding that when deforming the inputs in the first place.
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jimmosio · Dec 25, 2018 at 10:02 AM 0
Share

Thanks for the answer, but I already mapped the square to the circle. Turns out I copied down the formula wrong so there's that, but the problem still persists. I figured I'd do a GIF to show exactly what's happening: alt text The blue stick represents the GetAxis("hor"/"ver")s, while the pink one the "circled" axes.

There should be a white one for the raw axes but it coincides with the blue one.

In the GIF I am moving the stick around the edge at constant speed, and clearly the axes are not playing along.

This happens regardless of radial deadzone and clamping (I set them respectively to 0 and 4)

$$anonymous$$erry Christmas by the way

2018-12-25-10-57-01.gif (300.5 kB)
avatar image Eno-Khaon jimmosio · Dec 25, 2018 at 11:28 AM 0
Share

Hmm... on one hand, maybe I misunderstood exactly what you were going for. If your inputs are rounded (analog stick) and you need them to become squared, then you would potentially need a circle-to-square conversion (secondary link) ins$$anonymous$$d.

On the other hand, looking back over your original script sample, there may be a few issues there regardless.

For example, you wrote the x and y-axis scaling incorrectly. The square-rooted values need to be swapped.

 float horin = h * $$anonymous$$athf.Sqrt(1 - 0.5f * h * h);
 float verin = v * $$anonymous$$athf.Sqrt(1 - 0.5f * v * v);

... should be...

 float horin = h * $$anonymous$$athf.Sqrt(1 - 0.5f * v * v);
 float verin = v * $$anonymous$$athf.Sqrt(1 - 0.5f * h * h);


How does the behavior compare before mapping the inputs to a circle? In theory, a perfectly calibrated analog stick would logically only reach ~0.707 on each axis when held diagonally, so how clean of a circle does the hardware make in the first place?

Additionally, just for reference, does the ship rotate smoothly with a deadzone of 0 (and based on GetRawAxis(), logically), or does it still snap briefly? I've dealt with shoddy analog sticks before, so I hope to be able to rule out faulty hardware as well.

avatar image jimmosio Eno-Khaon · Dec 25, 2018 at 01:02 PM 0
Share

As I said in the reply, I've already spotted the error in the formula. In the OP I also said I tried with three different controllers, from good-as-new to shoddy, and still have the snapping issue. I tried them on a polished game and I'm able to use the sticks as I wish. Also come to think of it, square or circle input shouldn't matter, because in my case I don't care about the magnitude but only the angle , and that doesn't change with the transformation. I'm confident that Beat Hazard uses an input axis system as well and it doesn't seem to have the same snapping issue with the same controllers.

Show more comments

Follow this Question

Answers Answers and Comments

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Controller Joystick Hold Delay Logic? 1 Answer

360 Trigger Pressing both Triggers at the same time 1 Answer

Gamecube Controller joystick axis does not work? 0 Answers

PS4 Controller Y-axis is linked to L2-button? 0 Answers

Player Rotation is snapping 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges