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 /
  • Help Room /
avatar image
0
Question by lukas_werz · Nov 04, 2016 at 08:24 AM · rotationrotate objectrotation axisrotatingrotate-around

Rotate GameObject on specific axis

Hello together

I'm a Unity beginner, so my question is may easy to answer to you. But I'm struggling now for a while and don't know what to do else.

I want to implement a "Holographic Puzzle" for the Windows HoloLens. For that I want to rotate my puzzle Parts. Simplified my puzzle parts are just cubes. The user target these puzzle parts with "Gaze", a ray coming out of the users head in the direction the user is looking. If the ray hits an object (puzzle part), I draw an indicator to show that the user can rotate this object. This Indicator is on transformed to the plane which is hit. See Image below. For that I transform the indicator:

     // Assign gameObject's transform up vector equals GazeManager's instance Normal.
     gameObject.transform.up = GazeManager.Instance.Normal;

Indicator Now my problem: I want to rotate the GameObject if the user make a Gesture. This rotation should be around this GazeManager's instance Normal AND the rotation should be arround the center of the GameObject. See Image below.

alt text

I tried a lot and searched a lot, but nothing worked. I paste my actual code below. If someone can help me it would be very friendly

Thanks a lot, Lukas

Code:

 public class GestureAction : MonoBehaviour
 {
 ....
 private Vector3 startUpdateNormalPosition = Vector3.zero;
     private Vector3 startUpdateGazeOriginPosition = Vector3.zero;
 ....
 void PerformNavigationStart(Vector3 position)
     {
         Debug.Log("PerformNavigationStart");
         startUpdateNormalPosition = GazeManager.Instance.Normal;
         startUpdateGazeOriginPosition = GazeManager.Instance.gazeOrigin;
     }
  void PerformNavigationUpdate(Vector3 position)
     {
         // Debug.Log("PerformManipulationUpdate");
         // rotationFactor = GestureManager.Instance.NavigationPosition.z * RotationSensitivity;
         Vector3 navigationDirection = AppContext.Instance.AppState.NavigationStartPosition - position;
         float rotationMaximum = Mathf.Max(navigationDirection.x, navigationDirection.y, navigationDirection.z);
         Debug.Log("rotationMaximum: " + rotationMaximum);
       
         // Apply rotation to object
         //transform.Rotate(new Vector3(rotationFactor_X, -1 * rotationFactor_Y, rotationFactor_Z));
         // transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
         // transform.Rotate(rotationVector, rotationSpeed);
        // Vector3 worldRotation = this.transform.TransformDirection(AppContext.Instance.AppState.NavigationStartRotationAxis);
         Vector3 worldRotation = this.transform.TransformDirection(AppContext.Instance.AppState.NavigationStartRotationAxis);
         //  transform.Rotate(worldRotation, rotationSpeed);
         transform.RotateAround(startUpdateGazeOriginPosition, startUpdateNormalPosition, rotationMaximum*20*Time.time);
        
     }
 }


indicator.png (15.1 kB)
capture.png (314.2 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lukas_werz · Nov 04, 2016 at 08:34 AM

Sometimes I ask my questions just 5 minutes to early. I was really close. The correct rotation is:

 void PerformNavigationUpdate(Vector3 position)
 {
     Vector3 navigationDirection = AppContext.Instance.AppState.NavigationStartPosition - position;
     float rotationMaximum = Mathf.Max(navigationDirection.x, navigationDirection.y, navigationDirection.z);
     Debug.Log("rotationMaximum: " + rotationMaximum);

     // Apply rotation to object
     transform.RotateAround(transform.position, startUpdateNormalPosition, rotationMaximum * Time.time);
 }
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 Zodiarc · Nov 04, 2016 at 10:14 AM 0
Share

Wouldn't just rotating on the local rotation using

 transform.rotation.localRotation = new Quaternion.Euler(xRotation, yRotation, zRotation);

be enough?

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

ROTATION STOPS when i move the char on the air! 0 Answers

How to only slerp Y and Z, whilst independently rotating X 0 Answers

Make GameObject rotate around another around random axis but with fixed distance 0 Answers

Mixing transform.rotation and transform.rotate? 1 Answer

How to object rotate on a single axis towards another object? C# 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