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
0
Question by InceptionUnity · Feb 19, 2013 at 09:14 PM · rotation

Rotation left & right

Hello everyone,

I don't understand why my camera can rotate on the left and not on the right, here my code :

 float angle = Mathf.MoveTowardsAngle(transform.eulerAngles.y, transform.eulerAngles.y, Input.GetAxis("Mouse X")*50*Time.deltaTime);
 
 transform.eulerAngles = new Vector3(transform.eulerAngles.x,angle, transform.eulerAngles.z);


Thank for your help

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 ATMEthan · Feb 19, 2013 at 09:38 PM 0
Share

If you want to rotate it to the right, shouldnt that be a -50?

avatar image InceptionUnity · Feb 19, 2013 at 09:53 PM 0
Share

When I write -50, if the mouse go to the right -> it rotates at the left And when I write 50, if the mouse go to the left -> it rotates at the left too. But never rotates to the right :(

avatar image ATMEthan · Feb 19, 2013 at 10:01 PM 0
Share

:/ Sorry, I think my suggestion would make something spin from clockwise to counter-clockwise. $$anonymous$$y mistake.

2 Replies

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

Answer by robertbu · Feb 22, 2013 at 04:36 AM

With the limited amount of code here, I cannot figure out what is going wrong, but I do know that anytime I deal with eulerAngles, there are issues that I have to jump through. Let me give you an alternate way to solve your problem.

If you take either a screen point or a world point and convert it to viewport point, you can tell where the point is relative to the camera view. Values greater than 0 and less than 1 are seen by the camera.

Here is a sample script. Attach it to the camera in a new scene with some object to give you feedback about the camera rotation:

 public class RotateEdges : MonoBehaviour {
     
     private Vector3 v3Rot = new Vector3(0.0f,1.0f,0.0f);
     
     void Update () {
         Vector3 v3Pos = Input.mousePosition;
         v3Pos.z = 10;
         v3Pos = Camera.main.ScreenToViewportPoint (v3Pos);
         
         if (v3Pos.x < 0.1)
             transform.Rotate(-v3Rot);
         else if (v3Pos.x > 0.9)
             transform.Rotate(v3Rot);
     }
 }

Note the v3Pos I calculate with a ScreenToViewportPoint() call could also be done by using a point in the scene and a WorldToViewporotPoint() call.

If this does not work the way you want it to, reply to this post with the issues, and I'll give you alternate approaches.

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 InceptionUnity · Feb 22, 2013 at 05:28 PM 0
Share

Thank you very much robertbu !! I just modify transform.Rotate(-v3Rot) with add the arguments "Space.World" in order to rotate using the local vaue of the object.

Have a nice day :)

avatar image
0

Answer by Kiloblargh · Feb 20, 2013 at 12:37 AM

I don't understand why it even partially works.

You need to put the mouse input in the second argument (target) of Mathf.MoveTowardsAngle.

Right now you are moving transform.eulerAngles.y toward transform.eulerAngles.y, and that can't do any good.

Comment
Add comment · Show 5 · 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 InceptionUnity · Feb 20, 2013 at 09:55 PM 0
Share

Hello,

I have change my transform.eulerAngles.y by the mouse, but now I cannot go to the left or right. I upload a short video to illustrate my problem : http://www.dailymotion.com/user/Shikura95/1#video=xxnnre

Thanks

avatar image robertbu · Feb 20, 2013 at 10:50 PM 0
Share

I considered your question when it was first posted, and I watched your video just now. I don't understand what needs to be rotated and to what limits. Are you just trying to rotate about the 'Y' axis based on the mouse movement?

avatar image InceptionUnity · Feb 21, 2013 at 07:37 PM 0
Share

I create a new video about my first problem: http://www.dailymotion.com/video/xxofv5_unity-rotation-probleme-2_videogames When I go to the left (with left control hold) I can turn my camera to the left, but when my mouse go to the right, it's don't turn on the right.

It's clair enough robertbu?

avatar image robertbu · Feb 21, 2013 at 07:43 PM 0
Share

Clear enough. I can't look now, but I'll take a look later if someone else doesn't give you a good answer.

avatar image InceptionUnity · Feb 21, 2013 at 09:04 PM 0
Share

Thanks for your following :)

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

11 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Using a slider script to control an object's rotation? 1 Answer

Network rotation is laggy and slow 2 Answers

Animations preventing rotation 0 Answers

Rotating a character with the joystick of the controller 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