Search Unity

Question Getting Closest Point on Surface of SkinnedMeshRenderer for Ragdoll

Discussion in 'Scripting' started by JusticeKingCayden, Jan 1, 2024.

  1. JusticeKingCayden

    JusticeKingCayden

    Joined:
    May 5, 2018
    Posts:
    51
    I have a ragdoll, whose limbs are made of primitive shapes. For collisions, everything works well. However, say I want to shoot an arrow so that it sticks out of the ragdoll. The primitive shapes don't perfectly match with the body, so the arrow sticks in deeper or out more depending on the topology. Is there a way for me to figure out the closest point on the mesh itself, through some form of Raycast?

    From what I understand about Unity, Mesh Colliders only work on static objects. This means that I need to use Primitive colliders for joints, specially on ragdolls. However, is there an efficient way to find the Closest Point to the skinned mesh?

    One method I heard involves looping over every vertex in the mesh, and selecting the closest ones. While this may work for a dense mesh, any flat areas will be ignored. Another method I found involved finding the closest point for every triangle, which solved this. However, the performance is really bad.

    My current method is to just use the Primitive Colliders, but this looks very bad, since the hit points are completely off from the mesh's surface.

    Is there a faster method to finding this closest point?
     
  2. JusticeKingCayden

    JusticeKingCayden

    Joined:
    May 5, 2018
    Posts:
    51