How would you have the player lock onto specific sockets on the mesh and snap to different sockets of this type in the same mesh using the mouse? Like if you were locked onto the Subtarget_Left_Arm socket and move the mouse up it would switch focus to the
Subtarget_Head socket or if you move the mouse left it would switch to the Subtarget_Body socket.
Here is an example of the sockets added to a mesh and their locations
Hey there @random.user.name! First I’d recommend putting the sockets you want in an array to be able to work with them easier to work with, then using the Get Socket Location to get their location, after that’d I’d make some form of lock on using that location with Everynone’s setup here or another lock on tutorial resource depending on your game type:
Disclaimer: One or more of these links are unaffiliated with Epic Games. Epic Games is not liable for anything that may occur outside of this Unreal Engine domain. Please exercise your best judgment when following links outside of the forums.
you can detect mouse delta (direction and speed it is moving) with a few blueprint nodes. So you could say, if mouse delta > some value, get previous index in socket array.
if mouse delta < some value, get next index in socket array.
The term to google would be “get mouse delta, unreal blueprint.” I think you’ll find plenty of examples. There is also some function libraries on the market place that have helper nodes for this.
Is there some way to compare the mouse position to socket position? Like their x and y values on your screen? or can you project your mouse position from the flat 2D screen perspective out to the 3D world as a vector or something?
yes I think that is possible, I believe there is a node for converting cursor position to world position. It might be involved with the top down template if i remember correct.
Are you referencing the python get_sockets_by_tag? As that’s not useful at runtime, and I also believe those tags are from the tag manager that’s unique to static meshes. You can retrieve tags from a static mesh socket like this:
But since you’re using an SKM, I don’t believe there’s a tag manager for SKM sockets. I couldn’t find a node for it at least. As a workaround, I’d use common naming of them and just verify they exist in a test.
I see, thanks for clarifying that. In the mean time I just called all sockets from the mesh and then threw all of the target sockets into another array.
The next part of the question would be how to use the mouse to switch between sockets based on which one is closer to it that isnt already being targeted?
Depending on how you want the targeting to feel I’d do it one of two ways.
Snappy: This is as soon as you pick a direction, it can snap to the next target, a la fallout. Get the direction of the mouse movement, then check through the array of which sockets are in that direction, then check which is the closest by looping through and testing them (if it’s only 5 or so it’s not too big of a deal) then on complete of that loop relock onto the one determined to be the closest. I would utilize the Convert World Location to Screen Location node heavily here:
Freeform: This is much easier to do but also might be less tactile for some users. This would be disabling the lock on itself when the mouse starts moving, and when it stops run the lock on check again to the closest to the cursor and just relock that way.
Either using the method mentioned in Everynone’s post before that drags the view, or if you just want the cursor without dragging the whole screen you’d use both Convert World Location to Screen Location and Set Mouse position in conjunction.
I finally got the mouse targeting working. Thanks for all of the information to create the building blocks for it.
I first set a boolean for “Lock-on Mode” that toggles when I press the button.
Then when Lock-on mode is started, I get the targeting sockets I placed in the skeletal mesh with this function:
Then when in Lock-on Mode, switch the mouse controls from controlling the camera to comparing distance from cursor to each of the sockets when you move it.
This method compares the angle from cursor to each socket:
Though in the future, I should probably switch from projecting the cursor position to 3D space, to projecting the 3D space locations of the sockets to their positions on screen to compare distance from cursor.
Amazing work! Converting it to full 3D space instead of bringing it back to the viewport distance between points would definitely feel better in many instances if your enemies don’t have too many segments. It will be a bit of work getting the target swapping to feel good if targets can have segments directly behind each other in relation to the player.