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 goy · Nov 19, 2012 at 08:57 PM · rotationmesh

Rotation Problem, if Mesh gets a Parent

Hello everybody!

After spending hours with no results, I'm asking here for help. I have came across the problem, that I wanted to limit the rotation of a Canon to an Axis. For example on a Tank or on my Tower.

The funny thing is, if I write a simple Script with Euler-Rotation it works like a charme, but if I parent the cube, that should be obviously the cannon, to my Tower (precisely on the Pivot-Object), the hell breaks loose.

See the picture below. The right and the left Cube, have the same setup, except that the left one has the Tower, as its parent.

alt text

Here the Hierarchy

alt text

Before the cube, I use a fixated point for the rotation, so the cube rotates around its parent and not its center.

On top of that, I found another strange problem. If I change the cylinders position and select its parent. Gizmos shows me its location always on the center of the mesh, even tough the position hasn't changed a bit. Is this a bug? It only happens, when there is a Mesh-Renderer. Without a Mesh, Gizmos displays the position correctly.

The code for rotation (I limit the rotation to 20 degrees around the y-Axis)

 // Update is called once per frame
 void Update () {
     Vector3 look = Quaternion.LookRotation((target.position -  rotate.position).normalized).eulerAngles;
     if ((look.y > 180 &&  look.y < 350f)) {
         look.y = 350f;
     } else if (look.y > 10 && look.y < 180f) { 
         look.y = 10f;    
     }
     look.z = 0f;
     rotate.rotation = Quaternion.Slerp(rotate.rotation, Quaternion.Euler(look), Time.deltaTime*50f);
     Debug.DrawLine(rotate.position, rotate.position + rotate.forward * 20f, Color.white);
 }

Can someone please explain me this strange happening? Why does it only work without parents, that have also meshes? And in this example they don't even change its pivot-Angle, so the euler-Angles must be fine?

I'll attach the example on an answer.

image001.png (17.3 kB)
image002.png (11.5 kB)
Comment
Add comment · Show 1
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 goy · Nov 19, 2012 at 08:21 PM 0
Share

Here my problem about Gizmos http://goy.bplaced.net/data/image003.png

and here the example http://goy.bplaced.net/data/testScene.unitypackage

Here you can see my functional Tower, but the cannons still rotate independendly of the Pivot-Object. http://www.youtube.com/watch?v=OVlUd1HNFpo

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Nov 19, 2012 at 09:34 PM

http://www.ogre3d.org/tikiwiki/Euler+Angle+Class

The primary problem is that multiple combinations of euler angles can produce the same quaternion or matrix. This means that converting eulers into a quaternion then back to euler can give different (but equivilant) results than what you started with. This is often a problem when attempting to apply constraints to an orientation (such as limiting a camera's pitch).

you'll notice your trying to apply constraints to an orientation and converting eulers to quaternions and back.

Long story short you constant converting between quanternions and eulers is the problem. Pick a type of rotation and stick with it.

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 goy · Nov 20, 2012 at 07:03 AM 0
Share

Your link was helpful and I was afraid it would be something like this. But if I can't use the Euler-Angles, how am I supposed to limit the rotation to one axis? I only know the Rotate(axis, angle) $$anonymous$$ethod which adds to the already applied angle, but I need to set a calculated angle or limit it to a $$anonymous$$- and maximum range of degrees, it can rotate.

The only possibility I know to do that is, having another Vector-Direction with the original forward and the new Direction its facing to and call Vector3.Angle.

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

10 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

Related Questions

How to rotate a mesh collider? 0 Answers

How would I rotate an object without moving one of its faces (locking it) 0 Answers

Centering to main camera a clicked point on sphere 1 Answer

Mesh Rotation Problems 2 Answers

different axis for different objects? 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