Distance between points on specified axis?

Let me explain this with the picture:

How to get distance between these vectors, but only along specified axis? So it would return a distance just like if they were ON this axis.

I’m working on 3D Vectors, but this is a 2D example, just for simplicity.

Attempting to answer this live: Twitch

Edit: Whoops! Thought this was in the C++ section.

Assuming you have:

FVector Arrow;
FVector RedDotPosition;
FVector GreenDotPosition;

//The key is to normalize the arrow vector, so it doesn't scale your distances.
Arrow.Normalize();
float RedDistanceAlongArrow = FVector::DotProduct(Arrow, RedDotPosition);
float GreenDistanceAlongArrow = FVector::DotProduct(Arrow, GreenDotPosition);
float Distance = GreenDistanceAlongArrow - RedDistanceAlongArrow;

If you want displacement, then multiply it by your normalized Arrow FVector.

This works great, thank you very much! :slight_smile:

+1 For the attempt ;D Here is what I meant:

103524-untitled-1_exp2.jpg

this helped me so much. I’m building a vaulting system and was able to use these dot products to calculate where along a wall the player can mantle. THANK YOU