Switch between targets using mouse

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.

image

thanks that helps with part of the question, but what about changing targets using the mouse?

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.

thanks I’ll look into that.

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.

Bigtime is correct again! Using a function like this, you can get the hit location vector if you’re using a mouse for the clicking.

I think using the get_sockets_by_tag is the easiest way to get all the sockets I want into an array.

How do you add tags to a socket?

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.

I definitely want to have a snappier target system where it snaps to the body part when you begin to move the cursor towards that part.

Thanks that functions looks like it’ll be quite useful for this.

One more thing, how would you move the mouse to the socket location on screen or atleast directly set its location to it?

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.

Thanks, I’ll have to experiment with those options.

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.

1 Like

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.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.