I would like to transform a rigidbody's world velocity into a local velocity based on a normal direction.
When the rigidbody is moving towards and within a range of a object, I use a raycast to determine the hit position and normal of the face it will collide with. I have the velocity of the RB in world space, but I would like to have it in the normal's reference frame.
I know a Transform
component can do InverseTransformDirection()
, but seeing as the normal is most likely not aligned to its transform, this is not going to work.
I want to know the velocity an object collided with a face, but only in the face's normal direction. The outcome of this is to apply a force to the rigidbody in the normal's direction and thus stopping the rigidbody from moving any closer to the hit point. The force will be calculated by looking at the component of the rigidbody's velocity that is in the same direction the normal. My thinking is, that if I can get the RB velocity into the reference frame of the normal, it will be just the UP component that I need to look at: the speed the RB is moving along the normal towards the hit point.
If you can imagine (all in world space) a ball dropping on the floor: when this ball is one radius away from the floor, there will be a contact point and the normal will be perpendicular to the floor. To arrest the fall of the ball, a force in the direction of the normal is applied (so UP). The strength of this force is the down component of the velocity. If the ball was moving horizontally while dropping, the DOWN component of the velocity that matches the normal direction in this case is what I am interested in.
Basically I want the velocity of the RB that as seen from the normal along its axis. Almost like saying I want to transform the world space velocity into a local mesh face space, but only the UP axis.