Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 SudoSandwich · Apr 14, 2015 at 10:51 PM · rotationphysicseulerangleslocalrotationlocaleulerangles

Bike stay upright based on surface normal

I'm having issues thinking of a good way to align my bike to the surface its riding on by modify the local z axis, without messing up the rigidbody simulation. I am able to get my bike to balance by modifying the transforms local euler angles as such:

 var euler = transform.localEulerAngles;

 // Only works for staying upright relative to ground plane
 transform.localEulerAngles = new Vector3(euler.x, euler.y,  -steerLean);

The issue here is that when I go up a vert ramp the bike aligns, obviously, straight upwards. I cannot think of / recall a good way to keep the object upright but keep the rigidbody simulation intact otherwise.

I have tried to use Quaternion.FromtoRotation but this does not seem to want to play nicely. The object flops from left to right and eventually just falls over.

My bike uses WheelColliders and is working fine other than this issue.

alt text

Picture above for reference. The bike is moving and should be leaning to the right.

capture.png (79.4 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Spinnernicholas · Apr 14, 2015 at 11:14 PM

You can get the normal with WheelCollider.GetGroundHit.

You pass it a WheelHit and it fills it up with the current physics information, including the normal.

If both wheels are on the ground, to get the actually vector you want, you will have to average the two normal vectors. Otherwise, just use the normal for the wheel that is touch the ground.(WheelCollider.GetGroundHit return false if the wheel is not touching the ground.)

Or...

Add mass for the bike and a possible rider and place at their respective centers of mass. If tuned correctly, gravity will pull the the bike to the right angle, balanced by the bikes force against the surface.

Set the local up angle of the bike to the above calculated normal.

Comment
Add comment · Show 4 · 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 SudoSandwich · Apr 14, 2015 at 11:30 PM 0
Share

So, I understand the part about getting the normal of the two tires. The part I am struggling with is how to convert that vector to the local euler angle I need for the z axis of my bike.

avatar image SudoSandwich · Apr 14, 2015 at 11:50 PM 0
Share

I tried the mass idea and it is something I can work with. I applied force relative to the inverse of the average ground normal of the two tires and lowered the center of mass. Now to turn I am adding relative torque ins$$anonymous$$d of directly modifying the euler angles.

Thanks for the help

avatar image Spinnernicholas · Apr 15, 2015 at 12:19 AM 0
Share

Ok, cool, good, because I'm still struggling to work out the details of how to do the first one. Involves fun vector math.

avatar image Spinnernicholas · Apr 15, 2015 at 04:01 PM 0
Share

How is it going?

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

19 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 avatar image

Related Questions

Complicated Rotation Issue 1 Answer

how to apply overall rotation to collection of rotated objects 0 Answers

Why is my object's local x rotation not going past 90 degrees? 1 Answer

Fixing the rotation around a particular axis using Quaternions? 2 Answers

Get the Inspector's rotation of an object with code 0 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