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 Fattie · Nov 02, 2011 at 08:32 AM · physicsvelocityrelativevectors

SImply yet tricky question about RELATIVE VELOCITIES...

Here's a straightforward question for Unity EXPERTS.

Say you have two rigidbodys a and b and they have velocities. (Obviously a.velocity and b.velocity )

What is the usual idiom in Unity, to calculate the velocity of b, as seen from a ??

I assume the answer is simply:

 var speedOfBSeenFromA:Vector3;
 speedOfBSeenFromA = b.velocity - a.velocity;

Is this correct?? Can an expert please confirm this? Maybe there's something I don't understand about Unity?

Once again, of course I know how to add "actual" vectors in Newtonian space, as in high school physics class. My question is specifically: what is the usual Unity idiom? Thanks!

To be clear, by "relative velocity" I simply mean as any high-school physics teacher would think of it! For example: imagine B is heading "straight up" at 10 m/s, and A is heading "straight down" at 2 m/s. In this case, essentially 10 - (-2) = +12, which seems correct.

Note: it seems somewhat odd there is not a function "relative velocity" since it's so common, maybe I'm missing something? (I realise it's just one minus the other - maybe that's the reason they didn't include such a function?)

Note: there is the somewhat confusing function GetRelativePointVelocity which appears to give the velocity of something passing seem from a strictly stationary point. (Assuming I understand that function correctly.)

So, I appreciate a seasoned expert letting me know if I'm correct in that the answer is very simply b.velocity-a.bvelocity. thanks!

PS no need to calculate Einsteinien time dilation for velocities approaching c !! :)

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 CHPedersen · Nov 02, 2011 at 09:13 AM 1
Share

You need no unity expert to confirm this. There is a very short and concise Wikipedia article in this exact subject:

http://en.wikipedia.org/wiki/Relative_velocity

avatar image Fattie · Nov 02, 2011 at 10:27 AM 0
Share

Hi @Christian ! I truly thank you for your input, just to be clear, I completely understand vector mathematics and even a little physics! (I think I even majored in these things at University - but I was pretty drunk at the time! :) ) $$anonymous$$y question is, in fact is that "how it is done" in Unity idiom (considering all the usual problems that can arise), and indeed secondly, is there a specific function, and indeed thirdly is my understanding correct re the little-mentioned GetRelativePointVelocity function. Cheers!

avatar image syclamoth · Nov 02, 2011 at 10:30 AM 0
Share

There isn't an inbuilt function for this, as I'm sure you know from reading the documentation. I'm a little mystified as to its absence, but it's not too hard to write a C# extension method for adding the functionality in. Do you want me to post something, or is that enough for you?

EDIT: I did it anyway, just out of curiosity.

1 Reply

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

Answer by syclamoth · Nov 02, 2011 at 10:37 AM

Here's something for C# users- it adds methods to the Rigidbody class for comparing velocity with another rigidbody, as well as a variant for comparing velocity at a point (e.g, for collisions). I do like extension methods.

 public static class Utility {
     public static Vector3 GetRelativeVelocity(this Rigidbody body, Rigidbody other)
     {
         return (body.velocity - other.velocity);
     }
     
     public static Vector3 GetRelativeVelocityAtPoint(this Rigidbody body, Rigidbody other, Vector3 point)
     {
         return (body.GetPointVelocity(point) - other.GetPointVelocity(point));
     }
 }
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 Fattie · Nov 02, 2011 at 11:00 AM 0
Share

Hi @Sycla! To confirm, and to be clear, as far as you know (a) there's no built-in function and (b) in fact the usual idiom amongst developers is indeed just subtracting the two vectors - there's no "gotchya" associated with that? (For example, no bizarre gimbal lock problems, to pull an example out of the air, or whatever else specific to Unity - who knows. I assume not, but I'm just asking.)

avatar image syclamoth · Nov 02, 2011 at 11:44 AM 0
Share

Well, you can call it what you want... and no, there's nothing weird that can happen with this calculation.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Move Player Car in Forward Direction using Physics Force 1 Answer

Why is the relativeVelocity of a Collision always zero in OnCollisionEnter and OnCollisionStay? 0 Answers

Velocity Relative to Rotation 1 Answer

Adding multiple "global velocities" to an object 1 Answer

2d side scrolling problem 5 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