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 Ardito · Mar 12, 2015 at 04:11 PM · rotationangleconvertdegreessingle

how to convert rotation of an object in degrees X

I need only rotate the x-axis of an object to the mouse or touch, I'm currently using this code to rotate the object:

 Vector3 screenPoint = new Vector3 (Input.mousePosition.x, Input.mousePosition.y);
 screenPoint.z = -transform.position.z; //distance of the plane from the camera
 dragObject.parent.LookAt(Camera.main.ScreenToWorldPoint(screenPoint));

But you change x, y, z axes, I want to change only x-axis, or convert the x, y, z in a single angle x. So with y and z to 0 degrees

Does anyone have the same problem and managed to solve it? thanks in advance

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 NoseKills · Mar 13, 2015 at 12:17 PM 0
Share

It doesn't make sense to me that you are taking a screen pixel coordinate screenPoint and then setting its .z parameter to a world coordinate -transform.position.z and then converting the whole vector to world coordinates.

Is your camera looking along the Z-axis ?

You say you want to rotate around X-axis so is this code meant to make an object "look back at you" from the game world (facing towards the screen and looking up and down at the dragged object) ? Please explain more (screenshot?)

avatar image Ardito · Mar 13, 2015 at 03:00 PM 0
Share

I set the z coordinate, because this script is attached to the camera and not the object to rotate (that is dragObject), by setting the -transform.position.z raycast that part from the screen stops exactly at (x, y, 0 ), in this way the object rotates along the z axis, otherwise the object always point towards the camera.

I care rotate an object towards the mouse or touch by changing only a value ranging from 0 to 360 in degrees (I wrote x axis as an example and figure out how to fix it).

With the lines of code that I put in the post upper changed all 3 values of rotation.

I tried to use:

transform.Rotate

transform.eulerAngles

Quaternion.Euler

the object rotates, but is not facing the mouse.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ardito · Mar 13, 2015 at 03:59 PM

I resolved, I put the code I used and I hope to help someone in the future.

                             float ris = 0;
                             if(Object.eulerAngles.y == 270)
                             {
                                 if(Object.eulerAngles.x <= 90 && Object.eulerAngles.x >= 0) ris = Object.eulerAngles.x + 180;
                                 else ris = Object.eulerAngles.x - 180;
                             }
                             else if(dragObject.parent.eulerAngles.y == 90)
                                 ris = -(dragObject.parent.eulerAngles.x - 360);
                             Debug.Log((int)ris);
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 m4c0 · Mar 13, 2015 at 03:10 PM

Assuming it's a 3D world, why aren't you raycasting from the click position to an invisible plane and make it look at that point? This way, the plane defines the 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 Ardito · Mar 13, 2015 at 03:20 PM 0
Share

Is a 3D world, I have already tried to do this, but with poor results, you may kindly give me a practical example of scripting?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to rotate Character depending on the inclination of the platform or its parts? 1 Answer

0-360 Y degree from Vector3.Angle 1 Answer

90 degrees isnt? 2 Answers

Rotating A Character 180 Degress 1 Answer

Limit Object Angle 2 Answers


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