How can I measure distance from a spawned object to an element of a blueprint?
I need to be able to measure the distance between a newly-spawned blueprint (in this case, a bird stand-in on the left of the image) and two objects on a character blueprint (in this case, the hands of the character on the right of the image) to find which of the two are closer to the spawned object and by how much.
I've been doing a few hours of tutorials and trial-and-error without much success. I know it'll need raycasting and arrays, which I've used both in limited ways before. I'm hitting a wall whenever I try to get the raycasting to start at one object and end at another in another blueprint, and I don't have a clue on how to extract the distance for other calculations once that happens. Anyone with more experience with code able to help me out?
If you're just looking for distance between two vectors.... then you just subtract one vector from another, and get the size (VectorLength) in absolute (always positive) from the result.
So it basically looks like: VectorA - VectorB -> VectorLength -> ABS = distance in float form
Do that twice, one for each character point you're evaluating, and simply compare the results.
So, get the location vector of the bird and each character component's world location.
If your character's skeletal mesh has viable bone names (or sockets) for the L/R hands, you may want to reference their location instead of those components you have shown. This way you wouldn't have to maintain the data for "left hand" and "right hand" components.
"Mesh->Get Socket Location" and provide the exact name of the bone or socket from your character skeleton (if applicable). This is case sensitive.
Now, depending on how you're identifying the bird actor.... maybe you might use raycasts from your character just to confirm your player is looking at (or within range)... I'm not sure.. Your post doesn't really provide any information on how you got to the point of "I have object A and object B, now I need to find the distance between"
answered Apr 07 '17 at 03:23 PM
I used cast to NewBlueprint where the new blueprint was the left you got in the image you attached. Cast used to take the Static Mesh inside the blueprint. Then you need take world location of left hand, right hand and the static mesh. Then use the vector - vector to get the distance between x,y,z coordinate from one hand to the object after you need to take lenght to know the distance between one hand and the object and after you can store it in float variable and use how you need.
answered Apr 07 '17 at 03:44 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here