• 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 baris150490 · Dec 27, 2013 at 04:12 PM · parenteulerangles

How to limit a GameObject's angle?

Hi, i am trying limit a GameObjet's angle on z axis.There are two objects, A and B. B is a parent of A and A has a rotation code like the following;

 A.Rotate(0, 0, 1);

Since B is a parent of A it also gets rotated as A does but i do not actually see a change in B's angles in the editor?My first question regarding to this is why? And my second question is that how do i limit the angle of B on z axis but A keeps rotating itself.Note that B becomes a parent of A when a statement becomes true, like the following;

 if(bla bla == true)
 {
      B.parent = A.transform;
 }
 else
 {
      B.parent = null;
 }

Could anyone give me a comment about these questions?

Comment
Add comment · Show 9
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 robertbu · Dec 27, 2013 at 05:00 PM 0
Share

First, based on this code, you've stated thing backwards. B becomes a child of A given this code. B is a child not a parent. As for rotation in the editor, the values displayed are relative to any parent. This is true of position and scale as well. So if you rotate the parent, you will not see any change in the child rotation since what is displayed is the relative rotation between the two.

As for limiting rotation, you'd have to give more information about what you were limiting and the range of rotations allowed. Limiting rotation can be very tricky. Usually folks will clamp values on transform.eulerAngles, but this does not work for arbitrary rotuation.

avatar image baris150490 · Dec 27, 2013 at 05:10 PM 0
Share

Hello Robert you are very right, B is a child, how fool i am.Please let me explain what i am actually trying to do.There is a A that has a LookAt code like A.LookAt(C.position); and B becomes a child of the A when a statement becomes true.In this manner i am trying to understand when this statement becomes true which B becomes a child of A, how much did B rotate? Let me say that if B rotated more than few tours, ah like 500 degrees.What i am trying to do is see that angle value.So i can use it anywhere else.Or in another way what i want to know is that when a statement becomes true how much tour does A do?

avatar image robertbu · Dec 27, 2013 at 05:27 PM 0
Share

Unity does not keep track of this kind of rotation. Internally it uses Quaternions. If you want to know how many tours, you'll have to keep track of the rotation change frame to frame. How difficult this is to do will depend on 1) how you are rotating your object, 2) how many axes you are rotating on and 3) if you allow rotations in both directions or only one.

avatar image baris150490 · Dec 27, 2013 at 05:51 PM 0
Share

frame by frame :/ that should be a expensive to calculate right :( Since i use transform.LookAt it only rotates on Y axis so does the B nothing more.

avatar image baris150490 · Dec 27, 2013 at 05:56 PM 0
Share

One more question please, if i rotate the A like the following;

 A.Rotate(0, 0, 1);


when A exceeds 360 degrees i see that the value returs to 0.Does this value never exceeds 360 degrees? I can type 500 degrees in the editor and it rotates it that much of angle.But i don't see that change when i rotate any GameObject like the code above, how do i know how many tour did it turn?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rupeshpamaihgari · Dec 27, 2013 at 04:44 PM

If you are using rigidbody for your gameobject, check on freeze rotaion on z-axis

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 baris150490 · Dec 27, 2013 at 04:48 PM 0
Share

There are no components attached to them.I also do not know the angle value of B, it is unknown.I cannot see or check it.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Make a simple tree 1 Answer

Rotating a child and a parent, simultaneously 1 Answer

How to be sure that the parent's position is the same is the child's position? 0 Answers

After unchilding a Character controller, it becomes disoriented 0 Answers

Clone wants a Parent (c#)? 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