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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
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
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
1

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

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

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

Help creating restraints for an objects movement according to it's parent 1 Answer

Behave like another object is parent? 2 Answers

Pointing a child at an object using its parents rotation 1 Answer

Camera follow ball along cylinder 1 Answer

Unity camera follows player rotation 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