Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
This question was closed Jan 16, 2020 at 12:46 PM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
7
Question by runevision · Jan 21, 2010 at 01:32 PM · rotationphysicstransform

How to stabilize angular motion (alignment) of hovering object?

How do I stabilize the angular motion of a hovering object? I have a hovering vehicle that moves at some distance above the ground, controlled with the arrows keys. The problem is that when it collides with some object (like a building) its rotation gets shifted. When I am moving it after this, it moves according to its local space rotation.

How can I cause my Rigidbody to return back to its initial rotation where it is only rotated around the Y axis?

Comment
Comments Locked
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

  • Sort: 
avatar image
33
Best Answer

Answer by runevision · Jan 21, 2010 at 01:34 PM

You can use this script (C#) to stabilize your Rigidbody so it returns to an alignment where the local Y axis points upwards:

using UnityEngine; using System.Collections;

public class HoverStabilizer : MonoBehaviour {

 public float stability = 0.3f;
 public float speed = 2.0f;

 // Update is called once per frame
 void FixedUpdate () {
     Vector3 predictedUp = Quaternion.AngleAxis(
         rigidbody.angularVelocity.magnitude * Mathf.Rad2Deg * stability / speed,
         rigidbody.angularVelocity
     ) * transform.up;

     Vector3 torqueVector = Vector3.Cross(predictedUp, Vector3.up);
     rigidbody.AddTorque(torqueVector * speed * speed);
 }

}

With the script you can control both how fast the Rigidbody stabilizes and how stable or wobbly the stabilization is.

Note: If you only want to stabilize along one axis, you can project the torqueVector onto that axis. For example, to stabilize along the local z (forward) axis only, do this before applying the torque:

torqueVector = Vector3.Project(torqueVector, transform.forward);
Comment
Comments Locked · Show 11 · 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 YoshieMaster · Dec 19, 2010 at 02:49 AM 0
Share

Thanks, This worked great for me. You are a legend!

avatar image PraetorBlue · Dec 10, 2012 at 07:45 AM 0
Share

This worked beautifully for me thanks!

avatar image again · Mar 31, 2013 at 06:55 PM 0
Share

Works perfectly for me, thank you !

avatar image tswalk · Oct 21, 2013 at 03:39 AM 0
Share

wow, ok this totally corrected the issue I was having described here:

http://forum.unity3d.com/threads/206015-how-to-add-torque-to-correct-bank

by projecting the predicted vector onto the right axis!.. I just spent two days trying to understand Quaternions... my head is literally spinning in confusion.

avatar image cherub · Jan 09, 2014 at 10:41 PM 0
Share

Works Perfectly!

Show more comments
avatar image
0

Answer by Sasmaster · Jan 21, 2010 at 01:54 PM

Thank you so much . I am still quite new to 3d math in unity so i am having a hard time to figure out this stuff . Before your solution I actually decided to use Configurable Joint and cancel out angular x,z but the downside of it was that on collisions there was no angular change at all that have made these collisions to look unrealistic . Now that is exactly what I need .

Thanks once again !!!!!!!

Comment
Comments Locked · 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 runevision ♦♦ · Jan 21, 2010 at 04:23 PM 1
Share

You're welcome! :) Consider in the future to add comments like this using "add comment" to the answer you're commenting on, rather than adding it as a new answer (because your comment is not an answer to the posted question).

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Separate child rotation 1 Answer

How to rotate a rigidbody relative to another? 1 Answer

how to CORRECTLY position and rotate a gameobject in unity 2 Answers

Bouncing Ball Problem( bounces vertically forever) 1 Answer

Rotation-Trouble 4 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