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 magnusm · Oct 12, 2013 at 09:41 AM · rotationjavascriptrigidbodyquaternionfind

Finding A Rigidbody's Rotation Speed And Direction

Hi, quick question:

 speed = Vector3 .Dot (rigidbody.velocity , transform.forward )*50 ;

I have this for finding the velocity of my rigidbody, how could I do something similar to find out how fast and to which direction the body is rotating?

Many thanks :)
Magnus

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

Answer by MarkD · Oct 12, 2013 at 10:05 AM

Well to start it is simply to finds it speed in 'velocity'. you Don't need a Vector3 to is making stuff more complicated than needed. speed= rigidbody.velocity.magnitude; //This is more than enough, with magnitude it will spit out a //single float value and will be the same as your Vector3 //version and now to find your rotation speed you could use (note this is part of my own script and only enables to one axis at a time).

The >=0 means it is moving in the positive site of its rotation the

 private var lastRot:Quaternion;
 
 
 function Update(){
 
 //check if object is rotating
 if(transform.rotation.y != lastRot.y && transform.rotation.y-lastRot.y >=0){  
 your function here;
 }
 
 
 if(transform.rotation.y != lastRot.y && transform.rotation.y-lastRot.y <=0){  
 your function here;
 }
 
 
 lastRot = transform.rotation;
 
 
 }
Comment
Add comment · Show 2 · 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 magnusm · Oct 13, 2013 at 11:51 AM 1
Share

Sorry about the late reply man :P

It worked perfectly thanks!

avatar image MarkD · Oct 13, 2013 at 02:00 PM 0
Share

Ok, not a problem. Good luck with your code.

avatar image
7

Answer by Tomer-Barkan · Oct 12, 2013 at 10:30 AM

Just like you have rigidbody.velocity, you also have rigidbody.angularVelocity which gives you the "rotation velocity" (known in physics as angular velocity).

Read about it here:

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-angularVelocity.html

Comment
Add comment · Show 2 · 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 magnusm · Oct 13, 2013 at 11:25 AM 0
Share

Thanks for the response, sorry about the late reply :P

When using rigidbody.angularVelocity on my AI, it constantly reads 0 even when turning.

Does this have something to do with me using LookRotation to rotate the AI, ins$$anonymous$$d of an actual force?

avatar image Tomer-Barkan · Oct 13, 2013 at 11:32 AM 1
Share

Yep, thats it. angularVelocity like velocity is the settings used by the physics engine. If you rotate the object manually ins$$anonymous$$d of letting the physics take care of it, it will be 0.

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

17 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

Related Questions

why can't my Rigidbody not rotate on slopes? 1 Answer

Rotate Rigidbody to always face a force 0 Answers

Rotation using Quaternion.Lerp 1 Answer

transform.Rotate and Rigidbody.MovePosition 1 Answer

Rotation along the x-axis to that player can turn around? 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