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 anthot4 · May 31, 2018 at 09:16 PM · rotaterotate objectrotatearoundroationrotate rotation

Rotating a Gameobject In Three Axis Unity

Hi all,

I am trying to create a rotate tool in our game where the user can rotate a gameobject in three axis by clicking on one of the axis and dragging it to the desired rotation. Ideally I am looking to create a rotate tool very similar to the one in unity, but have become stuck as to the best way to achieve this. I have tried numerous rotation approaches from Quaternion.lookrotation to euler angles but none of them make the gameobject rotation correctly. If anybody has any ideas how to achieve this I would be very grateful. Please see below for how the rotation axis are on the gameobject at the moment:

alt text

image-13.jpg (24.3 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
0

Answer by anthot4 · Jun 01, 2018 at 08:02 AM

For anybody else who is in a similar situation the rotation method that is required is called "ArcBall rotation". I have found some information online which should help me achieve it, but it looks pretty advanced stuff.

Comment
Add comment · Show 2 · 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 hawksandwichgames · Jun 01, 2018 at 08:07 AM 0
Share

Based on your setup, you probably don't need something like ArcBall. With Unity's rotation widget, you can rotate on individual axis (like yours) OR you can just drag the ball and it calculates the axis you want based on that. That's where the advances stuff comes in, I think.

avatar image anthot4 hawksandwichgames · Jun 01, 2018 at 12:25 PM 0
Share

Thanks your you reply, I have tried rotating the gameobject on individual axis but it doesn't rotate the right way if I rotate multiple axis. The rotation doesn't seem to take it to account the object's local rotation value.

avatar image
0

Answer by hawksandwichgames · Jun 01, 2018 at 08:04 AM

Hey there, the way I'd go about it is by storing x,y and z rotation as separate floats then setting the object's rotation according to those values.

 float rotX,rotY,rotZ;
 
 void Something () {
   //first, change your values according to how the player pulls the widget.
 
   //now we'll give them the ability to loop around. I'm not testing this as I write it, so I'm not sure if going the full 360 is what works or not, but you get the idea.
   if (rotX > 360f) rotX=0f;
   if (rotX < 0f) rotX = 360f;
 
   if (rotY > 360f) rotY=0f;
   if (rotY < 0f) rotY = 360f;
 
   if (rotZ > 360f) rotZ=0f;
   if (rotZ < 0f) rotZ = 360f;
 
   //next, let's set the object's rotation
   obj.transform.rotation = Quaternion.Euler (rotX, rotY, rotZ);
 }
Comment
Add comment · Show 2 · 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 anthot4 · Jun 01, 2018 at 12:29 PM 0
Share

Thanks for your answer, I have tried a similar approach to this already but havn't tried setting the rotation to how the player changes the values at the start. I'll try this and let you know if it works.

avatar image anthot4 anthot4 · Jun 01, 2018 at 12:44 PM 0
Share

It didn't work sadly, please see below for the way I have done the code for it currently. I have an invisible plane which is perpendicular to brick for each axis. I then cast a ray from the users mouse position which hits a point on this plane which the brick then rotates towards. This works apart from the fact that the brick doesn't seem to rotate on its local axis when rotated on more than one axis.

if (Currentrotaxis == CurrentRotAxis.X) {

         RaycastHit Hit;
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);

if (Physics.Raycast (ray, out Hit, $$anonymous$$athf.Infinity, 1 << Layer$$anonymous$$ask.NameToLayer("RotationRayCast"))) {

             Vector3 difference = Hit.point - InstatBrick.transform.position;
          RotBrickX = $$anonymous$$athf.Atan2 (difference.z, difference.y) * $$anonymous$$athf.Rad2Deg;


         InstatBrick.transform.rotation = Quaternion.Euler (RotBrickX, RotBrickY, RotBrickZ);

avatar image
0

Answer by Unified2000 · Jun 01, 2018 at 12:59 PM

     Vector3 selectedAxis=Vector3.up;
     if (Input.GetMouseButton(0))
         transform.Rotate(selectedAxis*(-Input.GetAxis("Mouse X")+Input.GetAxis("Mouse Y")));
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 anthot4 · Jun 01, 2018 at 01:03 PM 0
Share

Thanks for your suggestion @Unified2000 . I'll give this a try later.

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

89 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

Related Questions

Flying player Rotates in the left and right direction not forward and back 1 Answer

360° Roation in one min 1 Answer

rotate object around another object 1:1 1 Answer

How can I make the player rotate with the camera so my movement keys don't get messed up because when I do rotate the camera the move keys go in different directions. 0 Answers

Rotate object in the direction where it is going 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