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 /
  • Help Room /
avatar image
0
Question by M4347 · Feb 05, 2016 at 12:50 AM · rotationaxisjoystickgamepad

Gamepad joystick rotation help needed, player turning strangely.

Hi,

I started making my game work with gamepad / controller today, but I'm having problems with getting the player to rotate using the right tumbstick on a gamepad. For keyboard and mouse I had been using ScreenPointToRay to set the players rotation and that worked fine, but I hadn't a clue how to make that work for gamepad so I did some looking around on here and found some code here;

     void Rotating (float jH, float jV)
     {
         if (playerRigidbody.velocity != Vector3.zero) {
             Vector3 targetdirection = new Vector3 (jH, 0f, jV);
 
             targetdirection = Camera.main.transform.TransformDirection (targetdirection);
             targetdirection.y = 0.0f;
             targetdirection.Normalize();
 
             Quaternion targetRotation = Quaternion.LookRotation (targetdirection, Vector3.zero);
             Quaternion newRotation = Quaternion.Lerp (playerRigidbody.rotation, targetRotation, 3f * Time.deltaTime);
             playerRigidbody.MoveRotation (newRotation);
         }
     }
 

Which does work allowing me to rotate the player with the analogue stick, but something isn't right, the player turns but then feels like it's sometimes trying to rotate back against you, or other times will reach a point in the turning cycle and just suddenly speed through the next 90 degrees. And when you let go of the stick the player doesn't stay in the last direction, it randomly keeps rotating for a bit. I'm very confused. I've tried it without using the targetdirectino = Camera.main bit as well, but the same result.

I've tried adjusting the Sensitivity in Input manager, and GetAxis and GetAxisRaw. The setup is an isometric game, so don't know if maybe it's something to do with that.

Really need some help getting this sorted.

Comment
Add comment · Show 2
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 Al_Goyle · Feb 09, 2016 at 08:47 AM 1
Share

What's up with that? Did you try setting up the transform.rotation ins$$anonymous$$d of the Physics? I think Rigidbody.$$anonymous$$oveRotation is supposed to be instantaneous but in my fair bit of experience with manipulating rotation I've never liked using the physics, even for an object otherwise propelled by physics calls.

avatar image M4347 Al_Goyle · Feb 09, 2016 at 01:45 PM 0
Share

I've just tried replacing rigidbody.rotation with transform.rotation & transform.rotation = newRotation ins$$anonymous$$d if that's what you mean? But I still get the same result, where I can rotate with the analogue stick, but the player models still doesn't act right, in that it still feels like its fighting back against the direction your turning. And if you release the stick the player model doesn't stay facing that direction, it will slowly rotate to a random direction then stop.

0 Replies

· Add your reply
  • Sort: 

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

47 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

Related Questions

X360 Controller detection gives uneven quadrants 0 Answers

my fps player rotation problem 0 Answers

Rotation is starting at 0, how do I use Math.Clamp() on it? 1 Answer

Rotate Joystick with camera 0 Answers

Problem with halt with rotating on y axis 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