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 Tritize · May 25, 2018 at 09:51 PM · rotationrigidbodymousemouse position

Continuously rotating horizontally a player with the mouse position

Hi!

I'm quite new with Unity and I'm struggling with an issue. So right now I have a player with rigidbody that I can rotate horizontaly using this :

 float _yRot = Input.GetAxisRaw("Mouse X");
 Vector3 rotation = new Vector3(0, _yRot, 0) * lookSensitivity;
 rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));

But with this, lets say I put my mouse to the left of the screen and don't move it anymore. The variable _yRot become something like -2, my player rotates until _yRot = 0 and now face the new direction.

What i'm trying to achieve is that if I put my mouse on the left and don't move it anymore (and _yRot = -2) : my player rotates to the left indefinitely at a speed proportional to _yRot. And I could make him stop rotating by placing the mouse in a "dead zone" at the center of the screen.

I'm learning and I have some issues understanding rotations, quaternions... If someone see what I'm trying to do and could give me some advice it would be really nice :) Thanks!

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 TanselAltinel · May 25, 2018 at 10:45 PM 0
Share

Sorry but I don't think I understand the issue. You want your player to rotate to a point indefinitely? How is that possible?

avatar image Tritize TanselAltinel · May 26, 2018 at 11:24 AM 0
Share

Well that was the question yeah, the code given by Tobychappell do it :) Like you "indicate a rotation direction" to the player.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tobychappell · May 25, 2018 at 10:53 PM

Consider trying something like this?

       Rigidbody rb;
       float lookSensitivity;
       float deadZone = 100;
       void Update()
       {
         float _yRot = Input.mousePosition.x - (Screen.width/2.0f);
         if (Mathf.Abs(_yRot) > deadZone)
         {
           Vector3 rotation = new Vector3(0, _yRot, 0) * lookSensitivity;
           rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
         }
       }
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 Tritize · May 26, 2018 at 09:36 AM 0
Share

Thank you so much! I didn't know the Input.movePosition command and was only finding some informations on how rotate the player with mouse but not with this line. It work just fine thanks :)

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

143 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 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

Object Look At Mouse 2 Answers

Player Rotation with the mouse 1 Answer

Having a first person player look at the mouse on the y axis 1 Answer

How can I rotate and move a cylindrical rod from one side with respect to other side? 1 Answer

why can't my Rigidbody not rotate on slopes? 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