Determine a vector point lies on two vector points

I have been stuck at this problem for at least 3 weeks. And what I’m trying to do is to determine whether a point is lying on two points (Point A, Point B – will use this 2 points to form a line). Then, I will use the mouse click event to capture Point C.

I have tried using the pointA and pointB to form an equation (y=mx+b), then I substitute the pointC into the equation. By right if the point is between pointA and pointB, it should return true. But sometimes, this method is not working.

//All the points are captured as vector

Does this have to be done with math? considering this is a game engine you could be using objects and tracing between A and B to see if they intersect an object C in the middle.

I’ve made you an example using objects.

link text

Inside you’ll find basically 3 actors: PointsAB, PointC, and PlayerController.

  • Player controllers creates PointC in the location you click, and lets PointAB know that it’s time to trace.
  • PointC dies after 2 seconds.
  • PointsAB exists as locations to cast to. Though I made it that only 1 of the two casts to the other, and detects if point C is in between the 2.

You can change the size of Point’s C capsule as you want. i didn’t change any value there.

There’s also a camera and a gamemode, but those two exists just to setup the level.

let me know if you have any doubts.

this is not necessary to be done with math. But I don’t know how to do it in another way. Can you tell me more about how to use objects and tracing in this situation?

@Evigmae i cannot open the zip file

but after I downloaded, it shows decompressing failed

do you have any idea on how to open it in 4.20? because I’m still a newbie with unreal engine

ok. i will try it

it’s the zip ue4 creates, nothing fancy about it, i just downloaded it and it opens fine for me

maybe its because it’s on 4.21, you’re on 4.20 i think?

well, no, you can’t… would have to download 4.21 to check it, sorry about that. i’m doing everything in 4.21 these days

For any future readers, you can detect whether point C lie on the line AB by getting the dot product between the AB vector and AC vector, it should result 0.