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 NAKAS · Jul 02, 2013 at 10:17 PM · rotationcontrolleraxes

Controller Axes Rotational Input

Hey i'm currently working on a skateboarding game and am trying to figure out the input for when the controller stick rotates around the perimeter of the game pad. It's for the start of pop shuv it tricks. Here are the motions i'm trying to map.

Thanks

alt text

screen shot 2013-07-02 at 4.03.05 pm.png (66.5 kB)
Comment
Add comment · Show 7
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 robertbu · Jul 02, 2013 at 11:08 PM 0
Share

I'm not sure this can be done. In particular run this code using your joystick:

 function Update() {
     var horz = Input.GetAxisRaw("Horizontal");
     var vert = Input.GetAxisRaw("Vertical");
     Debug.Log(horz+","+vert);
 }

What I see are values which remain the same around significant portions of the rotation. You could implement a clunky rotation, or a clunky rotation with smoothing, but I don't see how to get smooth, real-time analog input for this motion. What you want is unique x,y values from each position around the circle.

avatar image NAKAS · Jul 02, 2013 at 11:57 PM 0
Share

cool i did that... one value always is changing. i brought the controller down and did a full 360 around the outside perimeter. I think a rough rotation could be made. 0,0 0,-0.03728097 0,-0.07196278 0,-0.0990991 -0.06695437,-0.0990991 // start of rotation 0.3683774,-0.09050578 0.3780917,-0.08741732 0.2517123,-0.08672997 0.1642821,-0.08672997 -0.07666886,-0.09290995 -0.1641905,-0.09565628 -0.3390507,-0.0990991 -0.5625747,-0.0990991 -1,-0.0977183 -1,-0.06647014 -1,-0.03281781 -1,-0.003628639 -1,0.04244062 -1,0.06544982 -1,0.07540561 -1,0.07918447 -1,0.08742648 -1,0.08811077 -1,0.09188963 -0.8444771,0.09601063 -0.5237169,0.09704012 0.05733136,0.09841481 0.2905699,0.09841481 0.7570469,0.09841481 1,0.09806961 1,0.09291911 1,0.08811077 1,0.07712244 1,0.06441729 1,0.04896581 1,0.02595966 1,-0.0115285 1,-0.04174718 1,-0.07951745 1,-0.08054694 1,-0.09462678 //end of rotation

so this is clearly a pretty rough circle around with inconstant speeds. one of the values is constantly changing. What i need to do is take rough estimates of these values and connect them. I'm clueless on how to implement it but i know i need to make gates where if the input passes though all gates in a set amount of frames the trick is thrown. How would i make those gates?

Thanks, Andrew

avatar image robertbu · Jul 03, 2013 at 12:04 AM 0
Share

$$anonymous$$y controller did not have the values changing like this, so I'm concerned that this solution may only work with some controllers. As a starting point you might try $$anonymous$$athf.Atan2() and see how far off the angles are from what you want:

 angle = $$anonymous$$athf.Atan2(vert, horz) * $$anonymous$$athf.Rad2Deg;
avatar image NAKAS · Jul 03, 2013 at 12:31 AM 0
Share

One possible reason for the different values is that $$anonymous$$e was in a fixed update. Im currently using an xbox 360 controller but will try it with a ps3 controller once i get one hooked up soon. As far as the mathf.atan2 it returned 0 to 180 on the x axes and 5 to 175 on the y axes with the xbox 360 conch. ill most likely be able to test a ps3 conch tommorow and an ouya conch if they released mac drivers.

avatar image robertbu · Jul 03, 2013 at 12:44 AM 0
Share

If I do this with my controller:

  function Update() {
     var horz = Input.GetAxisRaw("Horizontal");
     var vert = Input.GetAxisRaw("Vertical");
     var angleT = $$anonymous$$athf.Atan2(vert, horz)  * $$anonymous$$athf.Rad2Deg;
     Debug.Log(angleT);
 }

I get values from -179 to 180 that map to a left-hand coordinate system rotation of the joystick. For me there are areas that don't change so the rotation values are not smooth. If you are trying for brisk movements, it might work.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by ebogguess · Jul 02, 2013 at 10:33 PM

You will have to measure and cache controller stick positions in your Update loop. You can use Input.GetAxis("Horizontal") and Input.GetAxis("Vertical") to get the x and y positions. By tracking many of these over time, you can analyze the pattern of motion. For instance, you'll know if the user has done a down stroke on the thumbstick if the current position is at the bottom, and the previous x positions were similar (within some threshhold) and y positions were trending down.

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 NAKAS · Jul 02, 2013 at 10:56 PM 0
Share

Thanks for answering. I have been tracking the positions. What im still clueless about is linking it all together by checking what the previous positions were . Right now i have it where if the vertical axes is less then -.09 do this. I need it to say if the axes are at zero and then go to -.09 do this.

avatar image
0

Answer by robertbu · Jul 03, 2013 at 02:11 AM

Here is a script that implements an immediate rotation. It expects the camera looking towards positive 'Z' and the rotates around the 'Z' axis. And it is a relative rotation, not an absolute rotation.

 #pragma strict
 
 private var rotating = false;
 private var prevAngle = 0.0;
  
  function Update() {
     var horz = Input.GetAxis("Horizontal");
     var vert = Input.GetAxis("Vertical");
     if (rotating) {
         if (Mathf.Abs(horz) < 0.99  && Mathf.Abs(vert) < 0.99) {
                rotating = false;
                return;
            }
            var angle = Mathf.Atan2(vert, horz) * Mathf.Rad2Deg;
            transform.Rotate(0.0, 0.0, -(angle - prevAngle));
            prevAngle = angle;
     }
     else {
         if (Mathf.Abs(horz) > 0.99 || Mathf.Abs(vert) > 0.99) {
                 prevAngle = Mathf.Atan2(vert, horz) * Mathf.Rad2Deg;
                 rotating = true;
         }
     }
  }

As expected, for my controller there are little dead zones. It works fine for brisk movements, but it is jerky for slow movements due to the dead zones.

Comment
Add comment · Show 2 · 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 NAKAS · Jul 03, 2013 at 06:15 AM 0
Share

This is certainly helpful. The problems are that it returns true for rotation even if a simple x axes move is made and it returns true for all rotations when I only need rotations on the outside perimeter . But it's definitely a helpful start. There is alot of power in $$anonymous$$athf.Atan2 and I believe once I figure out how to track input over multiple frames (in ebogguess answer) i should be able to get solid code that achieves what is needed. Im gonna get to the bottom of this tomorrow.

Thanks a ton

avatar image robertbu · Jul 03, 2013 at 08:22 AM 0
Share

If it is returning true for all rotations, then you need to decrease your Sensitivity setting in the Input$$anonymous$$anager for Horizontal and Vertical. Comparing 'horz' and 'vert' to 0.99 in the code above is to assure the joystick is towards the outside. For my joystick, I have the Sensitivity set to 1.5 for both Horizontal and Vertical. Do a 'Debug.Log(horz+","+vert)' and exa$$anonymous$$e where on your stick motion do horz and vert go to 1/-1.

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

16 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

Related Questions

Using an Xbox 360 controller for Rotation 0 Answers

How to keep the right sides while rotation 0 Answers

Maintain direction regardless of orientation (2) 1 Answer

click to move workig script!! but pls help with rotation!! :( 1 Answer

Sphere rotation in moving direction 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