Target point between 2 vector locations

I’m trying to find a point between my character’s location, and a targeted pawn’s location. I want the location between to be calculated by subtracting a certain amount from the pawns current location.

Ive tried just subtracting a flat number from x and y but that ends up making a fixed location that doesnt change even when my character changes his location.

Im assuming this starts with GetUnitDirectionVector, but I just can figure out how to calculate the middle point by subtracting.

My character is supposed to jump to that point and I want him to land basically X distance before the pawn from any direction he approaches from

MiddlePoint = CharacterLocation/2 + TargetLocation/2

Edit:

This will draw a line from a point exactly “Desired Distance” away from the pawn to the pawn itself.

2 Likes

I dont want the exact middle though. So how would I add say like 10 more units to that middle point?

10 more units in which direction?

10 units towards the pawn

What if the character and the pawn are 8 units away? (and the mid point is 4 units away)

Does this mean you have to get the point on the other side?

ok so what exactly is happening: SphereOverlap sphere scans for pawns. I get the location of the first pawn in that array. I then want my character to land in front of the pawn X units before the pawns world vector location, so my guy doesnt glitch into his model. I kind of figured it out, but for some reason my character doesnt land in the same spot everytime even though the pawns location is constant. It seems like the radius of the sphereoverlap is affecting where he lands which is strange.

Yeah i should have never once used the word middle in this question and I realize that now. I didnt mean the dead middle of the 2 locations. I mean a point that was certain units back from the pawn location which I assume needs to be subtracted but i dont know how

It has nothing to do with the middle then. The sphere will not affect the point unless you get no hit result.

I have edited my answer.

See if the second blueprint in the answer serves your goal.

Well Its half working i think. It doesnt seem like changing that float value does anything though. He keeps jumping just in front of the pawn. When I increase that he doesnt move back or forward any.

Sorry i dont want to lead you on a wild goose chase. I appreciate the help. Im using SetActorLocation as the final node thats taking this vector information

What values do you use for Desired Distance? If you use 10 it will not work.

Unreal uses centimeters by default. Set it at 200 and 700 and say if this makes any difference.

Ok yeah thats the results I was looking for. Perfect. Also ONE last thing if you can.

Im running that vector value into a lerp as value ‘B’ and my characters current location as value ‘A’

I also have a timeline that is increasing and dictating the value of ‘Alpha’ on the lerp.

For some reason the further you are away from the pawn with this timeline and lerp, he lands slightly further back and not in the same consistent spot like he does without the lerp.

Do you know whats causing this?

I want the character to travel over time to that final point rather than teleporting.

Can you screenshot me this setup? (the timeline curve too)

with this setup. He rushes very fast to point B. It doesnt seem like the timeline is having any effect

you know what I think I got sometthing thats close enough to what I wanted. I just reduced the Timeline value at 1 second to like .15. That slows the movement down. He doesnt land in EXACTLY the same spot everytime but its close enough I think. I guess if you have a suggestion thats better Im all ears, but thank you so much for your time and help!!!

It seems it should be working accurately.

There are 2 things I can think of that might cause different landing location:

  • If the character root transform and the target root transform are on very different heights the distance will be sloped since the vector is fixed length in 3D. The further away the character and the target are, the closer to the horizontal distance the vector will be. The way around this is to remove the Z components when you take the positions.

  • The timeline points might not be at exactly (0,0) and (1,1). Double check them by selecting them and typing the positions if needed.

Happy coding :slight_smile: