• 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 /
avatar image
0
Question by Arcatar · Mar 24, 2019 at 11:25 PM · rotation axis

Analog Stick Snapping

Hey there, I'm working on a topdown 2D game that requires smooth analog stick movement. I couldn't do anything about the deadzones, though. The values of the axis snap to 1, -1, or specific numbers when near 45esque's angles. Already stored 0 on dead zone on the Input Manager, tried code for radial deadzone (did everything this page had to say www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html) and changed joysticks. I'm currenly using a generic. Any ideas would be very much welcome.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by WarmedxMints · Mar 25, 2019 at 12:05 AM

I posted this a few days ago for someone here, it may help you. You could tighten up the regions;

  using System;
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public enum StickRegion
  {
      Centre,
      Top,
      TopLeft,
      TopRight,
      MiddleLeft,
      MiddleRight,
      BottomLeft,
      BottomRight,
      Bottom
  }
  
  public class InputRegion : MonoBehaviour
  {
      public List<Sequence> sequences = new List<Sequence>();
  
      private StickRegion _currentRegion;
      private StickRegion _lastRegion;
  
      public void Update()
      {
          var stickpos = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
  
          _currentRegion = GetStickRegion(stickpos);
  
          if(_currentRegion != _lastRegion)
          {
              Debug.Log(_currentRegion);
              _lastRegion = _currentRegion;
  
              CheckSequences(_currentRegion);
          }
      }
  
      private void CheckSequences(StickRegion region)
      {
          for(var i = 0; i < sequences.Count; i++)
          {
              //If the new region matechs the next region in the sequence
              if(region == sequences[i].sequence[sequences[i].currentIndex])
              {
                  //Advanve our index by one
                  sequences[i].currentIndex++;
  
                  //Count has reached the end of the sequence so all inputs matched
                  if(sequences[i].currentIndex > sequences[i].sequence.Count - 1)
                  {
                      //Do something when that combo has been performed
                      Debug.Log("Combo " + i.ToString() + " Success");
                      //Reset the index back to 0 ready for it to fire again
                      sequences[i].currentIndex = 0;
                  }
                  continue;
              }
              //The inputs did not match the sequence somewhere so we reset it back to the start
              sequences[i].currentIndex = 0;
          }
      }
  
      public StickRegion GetStickRegion(Vector2 stickPos)
      {
          if (Mathf.Abs(stickPos.x) < 0.3f && Mathf.Abs(stickPos.y) < 0.3f)
              return StickRegion.Centre;
  
          if(Mathf.Abs(stickPos.x) < 0.3f)
          {
              if (stickPos.y > 0.3f)
                  return StickRegion.Top;
              if (stickPos.y < -0.3f)
                  return StickRegion.Bottom;
          }
  
          if(stickPos.x > 0.3f)
          {
              if (Mathf.Abs(stickPos.y) < 0.3f)
                  return StickRegion.MiddleRight;
  
              if (stickPos.y > 0.3f)
                  return StickRegion.TopRight;
              if (stickPos.y < -0.3f)
                  return StickRegion.BottomRight;  
          }
  
          if(stickPos.x < -0.3f)
          {
              if (Mathf.Abs(stickPos.y) < 0.3f)
                  return StickRegion.MiddleLeft;
  
              if (stickPos.y > 0.3f)
                  return StickRegion.TopLeft;
              if (stickPos.y < -0.3f)
                  return StickRegion.BottomLeft;
          }
  
          return StickRegion.Centre;
      }
  }
  
  [Serializable]
  public class Sequence
  {
      public List<StickRegion> sequence;
      public int currentIndex;
  }


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 Arcatar · Mar 25, 2019 at 04:56 PM 0
Share

I'll mess around with it and let you know, thanks man!

avatar image Arcatar · Mar 25, 2019 at 05:21 PM 0
Share

It'd work great for an arcade game, but what I'm after is smooth analog movement. $$anonymous$$aybe I explained myself wrong. Analog sticks tend to 'snap' to specific numbers (1, -1, etc) when the axis gets near them. I'm trying to stop that.

avatar image WarmedxMints Arcatar · Mar 25, 2019 at 06:01 PM 0
Share

No, they do not. $$anonymous$$aybe it is something your gamepad does. I have only witnessed that behaviour on some Dualshock 3 pads. $$anonymous$$ost gamepads won't every report something like 1, -1 as the pots are rounded so you'll get something like -0.75, 0.75. What are you using for input management and what gamepad are you using?

avatar image Arcatar WarmedxMints · Mar 27, 2019 at 02:07 AM 0
Share

A generic gamepad. I'm using Unity's input manager to deal with it. And yes they do, otherwise this tutorial (www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html) would be pointless. Check the first circle picture; that's what I'm struggling with. I followed all those instructions I can't get the radial deadzone to work for the life of me. If it did, I would never get fixed numbers like 1's, -1's, or 0.75's, only numbers with plenty of digits because of the angles. Also thanks for helping, man.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

102 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

Related Questions

How to Rotate a game object towards the mouse click 3 Answers

Rotate 2d Sprite 0 Answers

2d character moves on the x and y-axis while only rotating at x-axis with joystick 0 Answers

Unity Rotations not working properly? Help.... 0 Answers

Rotating around self axis by n degrees ?? 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