Get closest socket of actor in front of player

So I am trying to work on a way to make the player ad an object to the nearest socket on the actor in front of them.

The way ive tried approaching this was making a sphere collision and get an array of all sockets inside the sphere, but I’m coming up dry on how.

Would anyone have an idea how to approach this, or am i even going at this in the right angle?

This is what i managed, but its not really working

One possible approach using a bunch of nested loops inside a function:

  1. Use a SphereOverlapActors node to get all the actors within a specific radius.
  2. Iterate over the Out Actors array output using a For Each loop (we’ll call this Loop A) and get their locations.
  3. Subtract their locations by the player’s location and normalize the resulting vector.
  4. Check the dot product of the normalized result with the player’s camera forward vector. Any value **above **zero indicates that the actor is in front of the player.

You can use a branch here to filter out all the actors that are in front of the player, based on the output from the dot product. If you just want to grab the sockets for all actors that are front of the player, then these will be your next steps:

  1. Cast to the actor and get a reference to its skeletal mesh.
  2. Plug reference to skeletal mesh into a Get All Socket Names node to get the socket names.
  3. Iterate over the Return Value array using a For Each loop (we’ll call this Loop B) and use the Get Socket Location node to return the socket location. Add each of these to an array of vectors (You could call this All Socket Locations).
  4. From the Completed pin on your first loop (Loop A), iterate over your **All Socket Locations **array using a For Each loop (we’ll call this one Loop C).
  5. Subtract the socket’s location by the player’s location and get the length of the resulting vector.
  6. A vector variable is needed to store the closest socket found so far. If this variable has not been set, then set it equal to the first socket in the loop. Then if any closer socket is found, set the variable equal to the current socket location within the loop.
  7. From the Completed pin on Loop C, return the value of the closest socket variable.
2 Likes