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

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!!! :)

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

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

Simple camera question -- follow rotation of object 1 Answer

How to orient object to road/itweenpath 1 Answer

Smoothing orientation to surface normal rotation 0 Answers

Why is Quaternion.FromToRotation() not working properly? 3 Answers

if x, make gameobject face player 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