Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Highlight Part of a Model With a Hit Box?

Discussion in 'Scripting' started by asterold, Aug 4, 2022.

  1. asterold

    asterold

    Joined:
    Mar 11, 2020
    Posts:
    5
    So, I'm making a game where parts of an enemy's body become highlighted randomly (think Fallout 3 Vats system) and the player can shoot the highlighted area to cause different effects:

    2022-08-04 14_45_22-Fallout 3_ VATS Montage - YouTube — Mozilla Firefox.jpg

    I know what you're thinking: isn't this basically just standard hit boxes? Yes, but I'm not sure how to make the actual part of the model have a "highlight" effect, and it should be noted, the highlighted parts won't necessarily be entire body parts, they could be half of a head, or the left kneecap, or just a chunk of the torso.

    Basically I would have several hit boxes over the parts of the model that I want to make into these targetable areas right? But then how do I make the parts of the model the boxes overlap over have a highlight effect?

    I have no idea how to accomplish this, so could someone please point me in the right direction?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,963
    To get a Fallout VATS type thing on animated stuff, I think these steps would take place at pause time:

    - bake the animated mesh to a new mesh:

    https://docs.unity3d.com/ScriptReference/SkinnedMeshRenderer.BakeMesh.html

    - use some kind of way to dig into that baked mesh and ONLY extract the parts related to the head, or arm, or whatever. This would require some way to reliably map the source mesh parts into the final bake. Hopefully when Unity bakes a mesh they don't change the ordering!

    - extract those verts / tris into yet another temporary mesh, presenting it with a MeshRenderer / Material.

    - I think at that point all you need is separate camera layering to show it always on top of the base model.

    You would have to deal with other things like partial mesh occlusion, like if the guy's head was partly behind a pole or something... again, more layering I suppose, or even Z-depth stenciling of some kind.
     
  3. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,596
    One way you could do this is create a second camera which only renders the part you want, and overlay that onto your view after applying a filter effect to it.
     
  4. asterold

    asterold

    Joined:
    Mar 11, 2020
    Posts:
    5
    Thanks for the input! But come to think of it, can't I just add a material to the collider box and make that flash in and out? I think that would have the same effect. Like, just make another gameobject over the arm, leg, etc. Then have a collider, then add a material that covers the exact dimensions of the collider?
     
    Last edited: Aug 5, 2022
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,963
    Sure, until you animate the character, then the colliders won't match so much.
     
  6. Runeheads

    Runeheads

    Joined:
    May 11, 2017
    Posts:
    10