Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Pzula · Jul 12, 2016 at 05:49 AM · rotationphysicsalignmentangularvelocity

Rotate Rigidbody to Rotation Via AngularVelocity

Hello all,

I'm looking to get a rigidbody object to align its rotation with another object by moving the rigidbody via angular velocity/forces. The rigidbody is not effected by gravity and is motionless in space.

Here's a breakdown of what I'm trying to achieve:

  1. Object A has a rigidbody

  2. Object B is a gameobject with a rotation

  3. Object A (Rigidbody) should add/set its angular velocity so its rotation matches Object B.

The rotation can be gradual.

The rotation is not limited to any axis; the object can rotate freely.

I'm really not great at rotations/quaternions and this is giving me a lot of problems.

Any help is much appreciated.

Thank you!

Comment
Add comment · Show 3
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 _Yash_ · Jul 12, 2016 at 08:44 AM 0
Share

try this code:

  float dir = Vector3.Cross(A.transform.forward, B.transform.forward).y;
  A.GetComponent<Rigidbody>().angularVelocity = new Vector3(0f, Vector3.Dot(A.transform.forward, B.transform.forward)*dir, 0f) * lerpSpeed;

adjust lerpSpeed to change how quickly it matches the rotaion of B.

avatar image Pzula _Yash_ · Jul 12, 2016 at 12:32 PM 0
Share

Hey, thanks for your response.

I gave your code a try and it works great, but it only rotates around the y axis. I tried implementing rotation for the other axes and while it worked at first, it becomes inaccurate at more extreme rotations.

avatar image _Yash_ Pzula · Jul 13, 2016 at 05:03 AM 0
Share

Okey, you are right,
other solution i can think of is this,

 void FixedUpdate(){
     // if this doesn't work try "B.transform.eulerAngles - A.transform.eulerAngles" below
     Vector3 difference = A.transform.eulerAngles - B.transform.eulerAngles;
     Vector3 velocity = difference / Time.fixedDeltaTime;
     A.rigidbody.angularVelocity = velocity;
 
 }

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.

Follow this Question

Answers Answers and Comments

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

Related Questions

Problems with rotating an object using angular velocity. 2 Answers

Gravity on a rotating platform 1 Answer

Rotating an Arrow 2 Answers

How to make any dice have a given face(int) face up? 1 Answer

How to make an object(cylinder) always at the center of an object(Terrain)? 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