x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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?

alt text

Product Version: UE 4.15
Tags:
untitled.png (410.9 kB)
more ▼

asked Apr 07 '17 at 03:02 PM in Blueprint Scripting

avatar image

Menelin
19 4 6 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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"

more ▼

answered Apr 07 '17 at 03:23 PM

avatar image

Jason.J
52 1 5 4

avatar image ErtieZone Mar 29 '18 at 04:55 PM

Just came to say THANK YOU. Vector length ---> ABS was key for me. I needed this for a similar issue.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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. alt text

a1.jpg (291.0 kB)
more ▼

answered Apr 07 '17 at 03:44 PM

avatar image

MK Studio
636 16 6 31

avatar image MK Studio Apr 07 '17 at 03:55 PM

I forgot cast to not work fine if you dont get a spawned object referecne. So make a variable for the blueprint on spawn and after use it to get static mesh

avatar image Menelin Apr 09 '17 at 01:39 PM

Thanks a ton for the help! i was able to store the player character's point locations as variables and sent them through a Blueprint Interface to the spawned blueprint. Those nodes for calculating distances between two vectors were a Godsend from there.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question