• 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 EddH · Aug 05, 2012 at 01:54 PM · rotationgravity

Rotating an object based on gravity and camera

Hi guys, I've been struggling away with this problem for far too long, so I'm reaching out for help now. I imagine the answer is fairly simple and there are probably many ways to solve it but I can't get my head around it. I'm also fairly new to all this...

The problem is the following:

I've got an object that is rigidbody cube that contains a child of a mouse look x player controller, then a mouse look y camera child in that, essentially an FPS setup (but not using the standard controller as gravity in that is fixed to only one axis). When the player clicks on a wall it changes gravity to that walls inverse direction (so the player falls towards the wall they click on). When the player lands it rotates the outside rigidbody cube to the same rotation as the wall it is approaching, so that the camera aligns to the walls direction and can move normal. On the whole this approach works, but I get an unfortunate side affect of spinning the cube on the wrong axis (thus spinning the camera in confusing directions) because the cube rotates to the walls rotation.

What I want is for the rotation only to occur in a 'natural way' which is partly a conceptual problem, but basically only rotate around one axis until the up (y axis) of the cube is pointing in the opposite direction to gravity, but since the cube can be changed to be any angle it could be any axis (I think?).

I've tried the following:

 transform.rotation = Quaternion.Lerp(transform.rotation,targetUp, Time.deltaTime * speed); 

 

where targetUp is the Quaternion rotation of the wall the player aimed at, it works, but this rotates other axis for obvious reasons. Also doing transform.up to match the walls' .up seems to make it spin in crazy ways too.

I'm not sure whether anyone can help with the information given? Any thoughts and help much appreciated! Can provide lots more info if anyone wants!

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

0 Replies

· Add your reply
  • Sort: 

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Shoot an object and have it move based on rotation 1 Answer

Rotation approximation issues using Quaternion.LookRotation 0 Answers

make child joint in joint hierarchy point upwards 0 Answers

Gravity on a rotating platform 1 Answer

Rotating Rigidbodies 2 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