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 /
avatar image
0
Question by PartyBoat · Dec 01, 2015 at 10:34 AM · camerarotationfpsquaternionjoystick

How do I properly rotate an FPS camera with a joystick?

So I've been looking around for quite a while now and it seems like there is no commonly understood way of using a joystick for FPS look controls. While I could find an endless number of FPS movement scripts and tutorials for mouse and keyboard I can not find one reliable script or tutorial to help me understand how to program look controls on a gamepad.

Here is the best I have come up with so far:

 originalRotation = transform.rotation;
 playerRotation = Quaternion.Euler(rightJoystickDirection.y, rightJoystickDirection.x, 0.0f) * originalRotation;
 transform.rotation = playerRotation;

Obviously this isn't right, and it doesn't even come close to working right, but again I'm at a loss as to how to use quaternions to rotate the player correctly.

What I really want to do is use a 2D vector (right joystick input) to rotate the camera a certain amount every second.

If anyone can point me to example scripts or tutorials that I can study to help get me closer to understanding what I need to know I'd be delighted.

Thanks!

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 Fattie · Dec 01, 2015 at 02:18 PM 0
Share

do you want the A$$anonymous$$OUNT of joystick lean to be the SPEED OF ROTATION? or do you want it to be (I feel this is more normal) that "any" joystick lean means it rotates that way (left or right) at some certain speed?

avatar image PartyBoat Fattie · Dec 01, 2015 at 05:19 PM 0
Share

Well once I finish this I actually want to have the amount of joystick lean (0 to 1) to feed into an exponential function that gives the speed of rotation a smooth ramp (this is how the best joystick-based shooters work like COD, full joystick deflection is orders of magnitude faster than say 30% deflection).

But I would be happy getting the rotation to work correctly at all right now ( a fixed speed would be fine).

avatar image Fattie PartyBoat · Dec 01, 2015 at 05:53 PM 0
Share

sure, all you had to say was "amount of lean" :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Falcon_DZ · Dec 02, 2015 at 09:47 AM

Rotation of FPS camera using right analog stick. i have a script for the camera rotation but have some issues with it. the camera automatically rotates and never comes to rest . i tried to manipulate my script but still get the same result. here what i have done!

     private void tryjoy ()
     {

             Vector2 joyInput = new Vector2 (Input.GetAxis ("4th axis"),
                                          Input.GetAxis ("5th axis"));

             float camX = _camera.transform.localEulerAngles.x;
         
             if ((camX > 280 && camX <= 360) || (camX >= 0 && camX < 80) || (camX >= 80 && camX < 180 && joyInput.y > 0) || (camX > 180 && camX <= 280 && joyInput.y < 0)) {
                 _camera.transform.localEulerAngles += new Vector3 (-joyInput.y * lookSpeed * .7f, _camera.transform.localEulerAngles.y,
                                                               _camera.transform.localEulerAngles.z);
             }
             transform.localEulerAngles -= new Vector3 (0, joyInput.x * lookSpeed, 0);
             _yRotation = joyInput.y;
             _cameraRefocus.GetFocusPoint ();
 

     }
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

43 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

Related Questions

Storing camera angles for a FPS -1 Answers

move the object where camera look 0 Answers

Rotation of player based on camera direction and joystick direction in 3D world 1 Answer

how to clamp y axis with Quaternion.Euler in unity 1 Answer

Gun not rotating with the camera? 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