# Vector projection problem

Hi guys,

I have an Actor with a bunch of Components (a BoxComponent and a few BillboardComponents which I use just for their positions).

Seeing this picture from the Top View, let’s say I have ComponentA which is in position V1, and ComponentB in position V2:

I need to find the position V3, also keeping into account that the Actor (and thus its Components) may be randomly rotated into the world (on its vertical axis only).

I tried a few different solutions, but none worked.

For example, I tried with vector projection, like this:

``````V1 = ComponentA->GetComponentLocation();

FVector V2Dir = ComponentB->GetComponentRotation().Vector();
V2Dir.Normalize();

const FVector& Projection = V1.ProjectOnTo(V2Dir);

V3 = V1 + Projection;
``````

Then I use the result to place the PlayerPawn, but the result is clearly wrong:

][2]

Is there something wrong in using ProjectOnTo() like that, or is there any other way to accomplish this?

I managed to calculate V3 using another function, PointPlaneProjection(). It works just fine, though it would be nice to know why the ProjectOnTo() method was not working for me…

Hey Varg978-

If the point you’re looking for is always going to be the cross section of the two components, you only need to look at the position (location) of the components. In the case of your screenshot (with X going in the up/down direction), the (X,Y) location of V3 would be at (V1, V2). That is, you can use the X of V1 and the Y of V2 to determine where V3 will be. As for the height of V3 (Z), this would depending on what exactly you’re trying to do, but you could simply get the actor’s Z and use that if you wanted V3 to be at the same height as the actor.

Cheers

Doug Wilson

Hey Doug, thank you very much for the explanation. Would your suggested solution work with arbitrary rotations of the Actor holding the Components?

Assuming the actor is rotating in place, this setup will move V3 back and forth on an X/Y diagonal. If you want V3 to stay in the same place relative to V1 and V2 such that V3 is revolving around the actor’s origin, then further math calculations would be necessary to determine that.