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
1
Question by Bodkin · Oct 30, 2015 at 10:54 PM · rotationrotate objectrotatearoundlocalrotation

Rotating an Object (Like Handle in Unity)

Unity Rotate Handle I want to rotate an object with the same affect as the Unity Rotation Handle.

The problem I am having is that when the object is flipped the rotation invert. I have managed to get the object to look at my mouse using Vector3.Dot and Planes but haven't found a way to check when to invert the rotation with the object.

I have looked into this script: http://answers.unity3d.com/questions/714203/rotate-object-via-script-like-in-editor.html but this rotate the object in world space. I would want to rotate it relative to the object.

I tried to change the values in the script above with this : http://answers.unity3d.com/questions/316918/local-forward.html

but then got a rotation that moved the object all over the place.

Thanks for the help!

capture.jpg (15.7 kB)
Comment
Add comment
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

3 Replies

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

Answer by BabilinApps · Nov 01, 2015 at 05:50 PM

You can do something like this to see if the object is flipped.

 if (Vector3.Dot(transform.up, Vector3.down) > 0)

Then you can make your script look like this:

 float _angle = 1;
 if(Vector3.Dot(Item.transform.up,Vector3.down) < -.5f){
 _angle *= -1;
 } //this sees how flipped the object is.
 Item.transform.Rotate(Camera.main.transform.right, Mathf.Deg2Rad * Input.GetAxis("Mouse Y") *
                          RotationSpeed * _angle);
 

I'm not %100 sure, it's been a long time sense I played with Vectors like that. Also it's untested code so please comment if you have a problem.

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
avatar image
0

Answer by Tom01098 · Oct 31, 2015 at 12:44 PM

If you want to rotate it around an object, then you can parent it to that object and rotate that object

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 Bodkin · Oct 31, 2015 at 09:10 PM 0
Share

I would want the object to rotate with the $$anonymous$$ouse axes and in local space. The problem is when the X Axis becomes the Y. or if the object is turned so that the positive movement moves the object the opposite way.

avatar image
0

Answer by starikcetin · Oct 31, 2015 at 11:22 PM

When the object gets flipped, duplicate angle with "-1". A sample of algorithm in 2D (x,y):

 float angle = Vector2.Angle (Vector2.right, target-transform.position);
         
 if ((target-transform.position).y < 0) 
 {
     angle *= -1;
 }


Comment
Add comment · Show 4 · 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 Bodkin · Nov 01, 2015 at 12:50 AM 0
Share

I will write songs about you! Thank you very much!

avatar image Bodkin Bodkin · Nov 01, 2015 at 01:08 AM 0
Share

How would I do it in Vector 3? When I use your method I realized that when I debug the code it all returns as 90. How do I implement it into rotation. such as

 Item.transform.Rotate(Camera.main.transform.right, $$anonymous$$athf.Deg2Rad * Input.GetAxis("$$anonymous$$ouse Y") *
                         RotationSpeed);
avatar image starikcetin Bodkin · Nov 01, 2015 at 01:29 PM 0
Share

You have 3 angles and 3 axises right? Then do the thing for all the 3.

Show more comments

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

37 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

Related Questions

rotate object around another object 1:1 1 Answer

Rotation Problem - Simulating Gimbal lock 1 Answer

Rotate object in the direction where it is going 1 Answer

90 degree rotation script, cant find or make one that works for my needs. 1 Answer

How to Rotate Object around point only 90 Degree. 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