Aiming at Individual Body Parts and Highlight Them

How would you create a targeting system that targets sections of an enemy’s body?
I.e. Head, Body, Left Arm, Right Arm, or any other section I would define.

Basically the steps would look like:

  1. Be able define separate body parts on the enemy so player can aim at and hit them separately.

  2. Once locked on have camera focus on that body part.

  3. Overriding normal camera controls when locked on, to be able to switch which body part is being targeted by using what used to be the camera controls. Basically snapping focus to new body part if you nudge mouse enough towards it.

  4. On the targeted body part, highlight it or put some sort of targeting reticle on it.

So… what is the question?

I guess we can start with how to lock-on to part of an enemy’s body

Have you defined how to determine what the body parts are, yet?

You might, for example, define some map from bone to body part, and when you find a particular bone, walk its parents until you find a bone in the table, and the part found in that table is the part for that bone. (That way you don’t need to define body parts for EVERY bone.)

Another alternative is to have a separate texture for the mesh, where the color of the texture maps to the specific body part.

A third is to build a separate skinned mesh for each body part (similar to how you’d build a dress-up paper-doll type avatar) and use the particular mesh instances to map to which body part it is.

What system to use to identify the body parts is one of the main things I’m trying to figure out. I did try the phys material method mentioned in this thread:

And I was able to confirm different body parts with a line trace to those phys materials. Is there a way change the appearance of those phys materials to have a highlight outline? Lots of highlighting objects tutorials I’ve seen use a highlight material to make the effect. Is that in any way similar to the phys material?

Also would I be able to focus the camera on each body part once detected using the phys material method?

Physics materials cannot affect render materials, but everywhere you specify a physics material, you could specify a render material in a parallel material slot.

So, you could swap out the material for a highlight material, or make your general “person” material already have some support for highlighting.
To draw an outline, you typically want to be able to render only the interesting piece into a customer depth/stencil buffer, and then use a post-process shader to emit the outline. So, you’ll need to insert materials that don’t render into the parts of the person that shouldn’t be hilited, or be able to only render the selected component some other way.

How would add the render material in a parallel material slot to the physics materials?

It depends on the specific component you’re using.

For the SkeletalMeshComponent, you set it here:
image

For a Material itself, you can also set it here:
image

The “physical material mask” is pretty cool; it lets you set different physical materials based on the color in the mask, which is helpful if you can’t separate each body part into a separate component.

so does the physical material mask let you differentiate materials by colors it defines? similar to weight painting in rigging or does it go by the color’s in the base material?