Hi
I think this is simple, but brain not working.
I have 4 possible spawn point and want to spawn closest to a Set Vector.
I could do it with a lot of if’s or but’s. If there a simple way to do this.
Hi
I think this is simple, but brain not working.
I have 4 possible spawn point and want to spawn closest to a Set Vector.
I could do it with a lot of if’s or but’s. If there a simple way to do this.
Distance Squared is the quickest way to get the distance between two vectors (as it avoids the square root a normal Distance calculation has). You’ll just have to loop through the available spawn points, grab the distance from each one, and select the lowest.
I don’t think there is any trick you can do that would let you evaluate all 4 vectors at once (unless you wanted to do some SIMD math craziness).
Hi Adept
How do you do I get x² in BP?
Subtract one vector from the other then do “Vector Length Squared”
What AdeptStrain is hinting at is the fact that if you just need the shortest distance without actually needing to KNOW the distance, skipping the square root saves some unnecessary instructions.
Even if you do need the distance it may be cheaper to use the distance squared to find it and then get the distance on just the “closest” point but you probably dont need to know if its just about finding the point.
All I am trying to do, is I have 4 spawn point around my character, front, left, rear and right.
On right click, I run a line trace under cursor and get the hit location, I am looking at which spawn point is the closest, and spawn my projectile based on that.
I was using get path length, but started to get very complicated, as with my code, I had to find the shortest distance, and then reference that back to spawn point and set that in a Var.
I am able to do this with a lot of And Bools, just looking for a simpler way.
Solved it,
Found a much easier way, Attached an arrow to a scene component, and on click, set world rotation, so my arrow point to where I click.
Should of down that a long ago.
Thanks for the help.