Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by dejafou · Apr 07, 2013 at 05:29 PM · inputgamepadshmup

How to get smooth rotation input from gamepad thumb-stick?

I am trying to write a input script for a twin-stick shooter that takes input from a gamepad on PC or Mac. When I rotate the thumb-stick 360 degrees the input returned rotates smoothly except at the axes (and sometimes the diagonals) where it snaps to the axes or diagnals.

I've attached a minimal project that exhibits the problem. Rotate the left thumb-stick slowly and you'll see the input vector snap to the axes. This is the relavant code:

 public class ThumbStick : MonoBehaviour 
 {
     
     Vector3 thumbStick;
     
     void Update () 
     {
         thumbStick = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0);    
         //thumbStick = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);    
     }
     
     void OnDrawGizmos ()
     {
         Gizmos.color = Color.blue;
         Gizmos.DrawWireSphere(transform.position, 1f);
         
         Gizmos.color = Color.red;
         Gizmos.DrawRay (transform.position, thumbStick.normalized);
 
         Gizmos.color = Color.green;
         Gizmos.DrawRay(transform.position, thumbStick);
     }
 }

I've tried:

  • Using both Input.GetAxis and Input.GetAxisRaw

  • Adjusting the Sensitivity and Type settings of the Horizontal and Vertical axes in the InputManager

  • A Logitech Gamepad F310 on PC and Mac

  • A PS3 controller on Mac

Is this something inherent in gamepad input that needs to be programmed around, or is Unity adjusting the data somehow (I could see how the snapping would be useful in other games)?

smooththumbstick.zip (237.7 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 Aldwin · Jun 09, 2013 at 03:34 PM 0
Share

I have exactly the same problem with a xbox 360 pad, using almost the same code with a "deadzone" :

     shootDirection = new Vector2(Input.GetAxis("HorizontalAim"), -Input.GetAxis("VerticalAim"));
     if (shootDirection.magnitude < shootData.shootDirectionDeadZone)
     {
         shootDirection = Vector2.zero;
     }
 
     shootDirection.Normalize();

I remember I didn't have this issue on XNA (I migrated my project from XNA to Unity 3D). If someone have an idea, I could help a lot!

avatar image moha · Jun 10, 2013 at 01:50 PM 0
Share

$$anonymous$$aybe if you try to make the move with a vector3.Lerp between the current position and the one you want to reach.

avatar image Aldwin · Jun 10, 2013 at 02:16 PM 0
Share

In this case, it's not about moving from an angle pto another but go directly to the angle given by the stick. And it's this angle returned by the stick which seems "snapped" around the 45° directions...

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Aldwin · Jun 11, 2013 at 12:08 PM

I just resolved my problem going into the Input setting and lower the "sensivity" value of the stick's x and y axis. It was set to 3 in my case and setting it to 1 just worked fine for me. All is smooth now !

Comment
Add comment · Show 1 · 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 dejafou · Jul 04, 2013 at 07:38 PM 0
Share

I was hopeful with this one, but it still sticks on the axes.

avatar image
0

Answer by zombience · Jun 10, 2013 at 02:39 PM

try something along these lines: I haven't tested this code out (written from memory), but I'm using similar code in my movement scripts and it's basically like this.

float deltaX; float deltaY;

 float sensitivityX;
 float sensitivityY;
     
 
 void Start()
 {
 
 }
 
 void Update()
 {
     deltaX = Input.GetAxis("horizontal") * sensitivityX;
     deltaY = Input.GetAxis("vertical") * sensitivityY;    
     Vector3 targetRotation = new Vector3(deltaX, deltaY, transform.rotation.eulerAngles.z);
     transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(targetRotation), .1f);
Comment
Add comment · 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
0

Answer by dejafou · Jul 04, 2013 at 08:29 PM

Ok, not sure what the protocol is for answering your own question, but here's what resolved my problem: In the input manager there are two horizontal and two vertical axes. One set is for keyboard and the other is for the joystick input. I was changing the settings for the keyboard input. Womp womp.

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

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.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

Using Xbox gamepad triggers as keys instead of axis? 1 Answer

horizontal menu + gamepad 1 Answer

Mapping multiple controllers 1 Answer

link gamepad to player 0 Answers

Getting R2 and L2 from PS3-Pad to Work on Android 0 Answers


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