Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
avatar image
2
Question by Maurdekye · May 26, 2016 at 12:56 PM · rigidbodyvelocityoffsetpoint

Get velocity of point offset from center of rigidbody

I have a cube with a rigidbody, and I can get the velocity of the entire cube with cube.GetComponent<Rigidbody>().velocity. But is it possible to get the velocity of a point on the cube offset from the center, say cube.transform.TransformPoint(0, 0, 1)? For example, a cube spinning in place would have a velocity of zero, but at the given point it might have a velocity perpendicular to the spin direction. Is there a built in method in Unity to do this, or do I have to program it in myself?

Comment
Add comment · Show 1
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 JedBeryll · May 26, 2016 at 02:26 PM 0
Share

I don't think there is but if you can find that point any time you can save the position and next frame get the position - last position. This of course means you get the result one frame later.

1 Reply

· Add your reply
  • Sort: 
avatar image
7

Answer by Bunny83 · May 26, 2016 at 07:42 PM

edit
Actually my initial answer was wrong. Unity actually has a method that does calculate this (Thanks to @Habitablaba).

It's called "GetPointVelocity". You just have to pass a world space point and it returns the current velocity of that point. If you have a local point you first need to transform it into worldspace by using transform.TransformPoint().

The following is my original answer where i (re)invented that method myself ^^.


No, there's no built-in function to return the temporary linear velocity of a given point. Of course that velocity would change each frame.

If you want to calculate it yourself you should keep in mind that physics are calculated in worldspace. To convert the angularVelocity into a linear velocity you have to calculate the distance of your point from the centerOfMass not from the object's origin because that's the point around the RB will rotate. Once you have calculated the tangential velocity you just need to add the linear velocity of the RB to get the final velocity for this moment.

There are basically two different ways how you could convert the angular velocity into a linear velocity:

  • either calculate the real tangential velocity so it will be perpendicular to the distance vector and the rotation axis

  • or calculate the next point where the point will be, following the actual rotation and draw a line between the current position and the next one. Of course this line will be slightly shorter as it's a chord of the orbit circle.

ps: the centerOfMass is given in local coordinates. It's the easiest way to calculate the distance vector in local space (P - centerOfMass) so you get a local space direction vector. Then just use transform.TransformDirection to get the worldspace direction.

edit

I quickly wrote this extension method:

 public static class RigidbodyExtension
 {
     public static Vector3 GetLinearVelocityAtPoint(this Rigidbody aRigidbody, Vector3 aLocalPoint)
     {
         var p = aLocalPoint - aRigidbody.centerOfMass;
         var v = Vector3.Cross(aRigidbody.angularVelocity, p);
         v = aRigidbody.transform.TransformDirection(v);
         v += aRigidbody.velocity;
         return v;
     }
 }

This should return what you want. You can simply use it like this:

 Rigidbody rb;
 Vector3 localPoint;
 
 Vector3 velAtPoint = rb.GetLinearVelocityAtPoint(localPoint);

Haven't verified everything is correct but first tests seems to be ok. The angular velocity is in radians per second and the resulting velocity is in units per second.

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 Habitablaba · May 26, 2016 at 10:55 PM 3
Share

I would also point out rigidbody.GetPointVelocity and rigidbody.GetRelavitePointVelocity

avatar image Bunny83 Habitablaba · May 27, 2016 at 12:43 AM 1
Share

Ohh, never seen those two methods ^^. For how long do they exist? Now i have to compare the output with my approach ^^. Thanks for the hint.

edit
:D Yes GetPointVelocity does exactly the same as my extension but it takes a world space point ins$$anonymous$$d of a local point.

GetRelavitePointVelocity seems to take a local point and returns a local velocity vector.

I'll edit my answer ...

avatar image Bunny83 Habitablaba · May 27, 2016 at 01:16 AM 1
Share

Strange, i just checked the oldest version of Unity i could find on my PC which was Unity3.0 and there GetPointVelocity already existed ^^. I have no idea how i missed those all the time :)

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scroll Ball Texture Smoothly 0 Answers

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Velocity of multiple rigidbody obiects in array 4 Answers

Question about rigidbody velocity 1 Answer

Unable to Apply External Forces to my Rigidbody 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