Finding intersection between two vectors

I’m a bit of a noob to Unreal so this might be a simple fix. I’m currently trying to find the point at which two vectors intersect (a door’s right vector and the door frame’s forward vector, which should create a ~90 degree angle) and set the door’s position where those two vectors intersect.

My problem is that when calculating this, the vector returned is always just happens to be the door’s relative position from its parent… What’s even weirder is that when using “SetWorldLocation” on the door, it sets it to a completely different position!

I have no idea why either of these two things are happening and it’s driving me nuts! I must be missing something small and silly :slight_smile:

Vector intersection formula:

247574-capture.png

Set the intersection point (Door Reset Position):

Then set the door’s position to that point:

247576-dd.png

Can you show a screenshot of the GetIntersectionPoint method?

You say you are getting the door’s right vector and the frame’s forward vector but you are just getting the world transform for both.
Also, I am very confused with your question. If I understand correctly, you want to set the door’s location once (maybe at the start of the game) so that it is precisely aligned with the frame? It doesn’t sound like you are trying to calculate a rotation for the door, such as for opening and closing it.
If what I understand is correct, and you just want to align the two meshes, probably the best thing to do is when you/someone 3d models it, use the origin as the corner point for the frame and the door, with the door offset so that it will fit into the modelled doorframe. Then, you can set the location of both meshes the exact same, and just add relative rotation to the frame to open/close it.

Perhaps a reason why your door was set to a completely different position could be that its origin is not where you might expect a door’s hinges to be. A way to check is simply by selecting the door and using the Move tool. Look at where the gizmo was created; this is its origin.

Setting the doors position to the intersection point probably seems pretty confusing without context. Setting it to that position isn’t exactly the end goal of the issue, but finding that location is a step that’s (what I believe is) necessary to complete the sliding door.

I need to set a sliding door’s position at various points in the door frame. The prob is I can’t just use the frame’s origin and add x distance in a direction; there are two doors with slightly different offsets from frame so the frame’s origin won’t always work. I’m sure there’s a simpler method if I just want to hard code it in, but I’m not a huge fan of that method :slight_smile:

I’m gonna post the GetIntersectPoint function in the comment above and it may make more sense after that

Here ya go. Warning: It’s a bit messy in it’s debug state!

You could attach to Sockets and RelativeTransform from there

That’s honestly probably the best way to go. It seems like the most simple solution tbh

Actually I checked the formula and it’s not working. Looking at it now I don’t even understand how it should work. You only calculate x and y of the intersection point.

I think the actual formula involves calculating the denominators of row matrices from the initial vectors

Hi,
(I was actually looking for such formula myself, so, you for that)

The formula you provided works but it doesn’t directly give the point of intersection between the two vectors. Instead it yields two values for the running parameter t for which the vectors intersect. If we define the two line (our vectors) equations as :

L1( t ) = p1 + t * d1

L2( t’ ) = p2 + t’ * d2

The point of intersection can be calculated with t1 or t2 like so :

Intersection point = p1 + t1 * d1 = p2 + t2 * d2

Always check that the two expressions give the same result, if not it probably means that the two vectors never collide.

Cheers