Finding Velocity at point but locally....

Hi, Im not sure why im finding this so difficult but I am for some reason.
I have a moving body which can go in all directions and I am trying to find the velocity in the X direction of a POINT on that object.

I can find the X Velocity of the rigid body by simply doing the following:

float xVel = transform.InverseTransformDirection(targetObj.GetComponent<Rigidbody>().velocity).x;

The above works fine, but this doesnt do at a specific point…

So I have tried so far:

leftVel = this.GetComponent<Rigidbody> ().GetRelativePointVelocity (leftPos.transform.localPosition).x;

But leftvel still changes depending on the direction of the rigidBody…

I have tried using just the GetPointVelocity and then inverseTransformDirection but I get the same problem?

I have tried the above but also transforming the local leftPos but same problem…

What am i doing wrong?

Thanks

I am assuming that you are trying to get the point velocity relative to transform.left of the rigidbody.

I look at your code and I cannot see what is going wrong . If local to world space transforms, coordinate systems, the meaning of .x in local space, confuse you, and have unexpected results, you are by no means alone – I have the same problem and I’m no girl next door.

This is why I generally discourage using .x, .y, .z components if at all possible – there’s no reason to make yourself dependent on a coordinate system when we have vectors and quaternions. There’s a simple and slick way of doing this that will give you the point velocity no matter what.

My suggestion (not tested) is to start by trying this:

leftVel = Vector3.Dot(
    this.GetComponent<RigidBody>().GetRelativePointVelocity(leftPos.transform.localPosition),
    this.transform.left
);

If the code is doing what you think it is doing, this should give you exactly the same answer as getting the .x component. In that case, I suggest taking a close look at your object’s behavior – maybe that makes sense.
However, I have a hunch it’s not doing what you think it’s doing, and I’ve run into problems with using components in unity before, which is why I stopped.