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 DanMarionette · Jan 24, 2012 at 11:14 AM · rotationphysicsrigidbody

Rigidbody Rotation Problem

I have a rigidbody with wheelcolliders and I am using a spline (Super Splines) to guide the rigidbody round a track. It's not been without problems, fighting with the physics but, I have a solution I am happy with a seems stable. The last issue I am having is with rotation of the rigidbody whilst in the air to do a flip. It can rotate forward or backwards up to 90 degrees and then just flips out. I am controlling the Y axis via a point on the spline, trying to lock the Z axis down to stop any tipping from side to side and then I want to leave the X axis to the physics.

Here are the methods that make this happen,

 void HandcarRotation()
 {    
     float rotationX = myTransform.rotation.eulerAngles.x;
     float rotationY = splineRotation.eulerAngles.y;
     float rotationZ = myTransform.rotation.eulerAngles.z;
     
     myTransform.rotation = Quaternion.Euler(rotationX, rotationY, rotationZ);
 }
 
 void SetToSplinePosition()
 {
     //set the local x velocity to zero to help prevent sliding off the spline
     Vector3 localVelocity = myTransform.InverseTransformDirection(myRigidbody.velocity);
     localVelocity = new Vector3(0f, localVelocity.y, localVelocity.z);
     myRigidbody.velocity = myTransform.TransformDirection(localVelocity);
     
     //set handcar position onto spline
     Vector3 position = new Vector3(splinePosition.x, myTransform.position.y, splinePosition.z);
     myTransform.position = position;
 }
 
 void LockZRotation()
 {
     //freeze localz rotation
     Vector3 localRotation = myTransform.localRotation.eulerAngles;
     localRotation = new Vector3(localRotation.x, localRotation.y, 0f);
     myTransform.localRotation = Quaternion.Euler(localRotation);
 }
 
 void TiltControl()
 {
     if(!IsGrounded())
     {
         float tiltDirection;
         tiltDirection = Input.acceleration.y;
         
         myRigidbody.AddRelativeTorque(Vector3.left * tiltDirection * tiltForce, ForceMode.Acceleration);
     }
 }

If I had to guess I would say it's something to do with local and world coordinates but, I'm not sure how to fix it.

Thanks for your help

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
Best Answer

Answer by DanMarionette · Jan 29, 2012 at 07:19 PM

I have found the solution. After trying lots of things with code I found some info about the X axis having trouble past 87 degrees. I have no idea of the details of what causes this and how it can be prevented but, to solve my problem I have rotated my vehicle 90 degrees on the X axis making X now forward and Z right. This way I can lock X and rotate on Z and get the effect I want. Z doesn't seem to have the same 90 degree limitation X has.

Like I said I don't fully understand why but, I have seen similar questions mentioning the same issues.

Thanks

Comment
Add comment · 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
0

Answer by Rapport-Noize · Feb 06, 2018 at 03:07 AM

GimbaLock?? you are working with vectors or eulerangles? why not try with quaternion for fix gimbal lock?

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

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

Rotating a Rigidbody with Physics 1 Answer

How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer

How to keep rotation from switching between - and + after a 360? 0 Answers

How do i keep a rigidbody upright? Looking for best way to freeze rotation 1 Answer

Freezing Rotation and Joints (Swing / Rope) Physics Issues 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