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
1
Question by hawken-2 · Nov 22, 2011 at 01:29 PM · rotationvector3quaternion

self righting object

Working on getting an object to self right, firstly the object is rotated to a random Vector3, then it should self right.

 function Selfright () {
     var pointUp = Quaternion.RotateTowards(gameObject.transform.rotation, upobj.transform.rotation, Time.deltaTime * 40);
     gameObject.transform.rotation = pointUp;
     }

Unfortunately this will make the object point in the Z direction of the upobj, all I really need to do is make the object self right. (point up over a duration of time)

Comment
Add comment · Show 2
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 aldonaletto · Nov 22, 2011 at 01:36 PM 0
Share

Do you want to rotate the object to a random point during some time, then return to the previous direction?

avatar image hawken-2 · Nov 23, 2011 at 09:12 AM 0
Share

here's the random rotation code:

gameObject.transform.rotation = Quaternion.LookRotation(Vector3(Random.value,Random.value,Random.value));

2 Replies

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

Answer by aldonaletto · Nov 26, 2011 at 04:59 AM

You could use physics to emulate this "inflatable punching bag" behaviour - but instead of applying the weight to the bottom, you could apply a constant up force to the top with AddForceAtPosition. The script below does exactly this effect with a capsule with rigidbody:

var force: float = 5; // up force var offset: float = 1; // offset from object's position (up direction)

function FixedUpdate(){ var point = transform.TransformPoint(offset Vector3.up); rigidbody.AddForceAtPosition(force Vector3.up, point); } You can tweak the effect with offset: the higher it is, the faster the object will self right. You can also increase the Drag factor in the rigidbody to make it stop swinging in less time.

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 hawken-2 · Nov 26, 2011 at 08:48 AM 0
Share

Thank you, this had the desired effect.

avatar image
0

Answer by Nonakesh · Nov 22, 2011 at 08:39 PM

I'm currently not on my PC, so I can't test if this works, but you should try this:

 function Selfright () {
     var pointUp = Quaternion.RotateTowards(gameObject.transform.rotation, Quaternion.LookRotation(upobj.transform.up), Time.deltaTime * 40);
     gameObject.transform.rotation = pointUp;
 }

If you don't want to set a custom up direction you could replace it with Quaternion.LookRotation(Vector3.up)

Comment
Add comment · Show 3 · 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 hawken-2 · Nov 23, 2011 at 09:11 AM 0
Share

Thanks for the feedback, seems this approach makes the objects Z axis (front) point up. Also the object aligns it's self so that it's X (left, right) is perfectly rotated to 0 (Z is rotated to zero)

The effect I'm looking for is more like one of those inflatable punching bags, it right's it's self by having a weight in the bottom, but isn't limited in what directions any of the faces point at.

avatar image Nonakesh · Nov 25, 2011 at 07:27 PM 0
Share

$$anonymous$$aybe you could try to change only x and y, so the left-right rotation still stays the same!

avatar image hawken-2 · Nov 26, 2011 at 08:49 AM 0
Share

I tried something along those lines. Was more of a hack really.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Rotate Raycast on Quaternion 1 Answer

Perpendicular Vector3 0 Answers

Quaternion amount/value of rotation? 2 Answers

How to know if a gameobject is rotating? 1 Answer

Quaternion.Euler rotations don't add up 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