• 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 HeywoodFloyd · Jul 31, 2013 at 05:14 PM · rotationorientationlocal axisworld coordinates

How to keep an object level to horizontal?

I'm modeling something like a camera jib, essentially, an articulated arm ends with a platform always level to horizontal. The platform has to rotate and move with the arm it's attached to, just remaining level.

This seems like it would be an easy problem, but nothing behaves the way I expect. I tried a script something like this:

   void Update ()
   {
     //Get the world up vector in local coordinates.
     Vector3 localUp = transform.InverseTransformDirection(Vector3.up);
     //Get the angle we need to rotate to get local up vector aligned
     //with world up vector.
     float angle = Vector3.Angle(Vector3.up, localUp);
     transform.Rotate(angle, 0, 0, Space.Self);
     
   }

This does not work. In fact, what this does is make the platform spin around.

I've seen other people with a similar problem and it was recommended to do stuff like transform.up = Vector3.up which also affects the other rotations, so the platform doesn't appear to be properly attached to the arm.

Surely somebody has solved this problem.

alt text

jib.png (18.7 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by HeywoodFloyd · Jul 31, 2013 at 07:28 PM

Solution is embarrassingly trivial:

   void Update ()
   {
     Vector3 eulers = transform.eulerAngles;
     eulers.x = 0;
     transform.eulerAngles = eulers;
 
   }
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 HunGARE · Apr 04, 2015 at 12:53 AM 0
Share

Thank you so much!!! :)

avatar image
0

Answer by chronicfail · Jul 31, 2013 at 07:05 PM

it might work to add a kinematic rigidbody to the horizontal object and set the constraints to freexe the x and z rotations.

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 HeywoodFloyd · Jul 31, 2013 at 07:30 PM 0
Share

thanks. Don't know if I tried that. I did implemented a pendulum, which kind-of worked, but always swung too much.

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

16 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

Related Questions

orienting player in one direction 1 Answer

Getting the orientation of Hit triangle? 1 Answer

How to change the way an object is facing when its rotation is 0,0,0? 2 Answers

Simulating different gravity, how to make falling platform fall in the desired direction? 1 Answer

How do I control particle orientation? (legacy vs shuriken) 3 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