• 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
Question by murkertrer · May 19, 2016 at 12:45 AM · rotationpositionquaternionparentorbit

Detecting the rotation of the current object? Shield resets when undertaking orbit.

So I'm trying to implement a 3d shield. For it, I'm using the orbit script at the wiki that is usually for cameras.

It works pretty good except that each time that I re-initiate control of the orbit the shield just resets to some position, insted of starting where it left off. The problem is the x variable in the following code:

 Quaternion rotation = Quaternion.Euler(y,x, 0);

The object is a child of an object. I manipulate it when I press mouse button1.

I was trying to pass the x value of the parent.transform.rotation.y but this would not do it :( Any ideas?

Here is the full code of the manipulation. Thank you for the time!

     void LateUpdate()
     {
         if (it && Input.GetKey (powerControll)) {
             
             Orbit ();
         }
     }
 
     void Orbit() 
     {
         if (Input.GetMouseButton (1)) {
             x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f;
         }
         y = at.myArm.transform.localEulerAngles.x *-1;
         Quaternion rotation = Quaternion.Euler(y,x, 0);
         Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
         Vector3 position = rotation * negDistance + at.myBall.transform.position;
         it.transform.rotation = rotation;
         it.transform.position = position;
     }


Comment

People who like this

0 Show 0
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

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by murkertrer · May 19, 2016 at 04:34 PM

Hi there, Thank you for your time. I coulden't use your methood because I was multiplying a Quaternion by a Vector, so I coulden't just rotate.

I just managed to find a solution. I checked the parameters as you suggested, and I found that I could pass the x, as the current euler Anlges of the shield, in the y axis.. Thank you again XD

                 x = (it.transform.eulerAngles.y - 360);
 
Comment

People who like this

0 Show 0 · 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

Answer by destructivArts · May 19, 2016 at 03:55 PM

When you call

 it.transform.rotation = rotation;

you are setting the rotation to some value which never took into account the initial rotation of the shield. ie. Look at your definitions of rotation and x. They don't look at the transform of the shield.

What you have defined (I think, because I don't know what at.myArm is) is how much you want to offset the shield this frame. To clarify, if x equals the change in mouse position this frame times some speed, then you probably want to map that to the change in shield rotation this frame. What you are doing now is setting it equal to the actual rotation value of the shield which will always start based around 0.

Try calling this instead:

 it.transform.Rotate(rotation);

If the rotation is still somehow incorrect, either go back and look at your definition of y (I only say this because its based on something I can't see in your code) or try:

 it.transform.Rotate(rotation, Space.Local);

or

 it.transform.Rotate(rotation, Space.World);
Comment
murkertrer

People who like this

1 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

51 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

Related Questions

How to write a script to disable position and rotation tracking for VR 0 Answers

Where to find original unity Parent/Child script? 2 Answers

How to Decompose a TRS Matrix? 3 Answers

How can I make a First Person Character Controller a child of a moving platform without it affecting the rotation of the Character Controller. 1 Answer

Rotation issue with remote players projectiles 0 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