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 !! :slight_smile:

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));
	}
}