Headshots on characters with ragdoll setup?

Hi there!

Just more of a concept question. If a character uses a capsule collider for it’s main collision needs, and have a nested 3d model with ragdoll setup (disabled while ingame, to be enabled when dead), how to check if this character received a bullet-head collision?

you use multiple collision layers in this case.

You’d probably need something like “bullets”, “level geometry”, “navigation collider” and “body collider”.

In this case, “bullets” could collide with “level geometry” and “body collider” while “navigation collider” would collide with “level geometry” (and other “navigation colliders”). LEvel colliders would be “level geometry”, player capsule would be “navigation collider”, projectiles would be “bullets” and ragdoll colliders would be “body collider”.

You can also use masks for collision query…

1 Like

I read your question slightly different than @neginfinity . If the ragdoll is not on until hit the head collider won’t be there. In that case you can get the hit data from the capsule collision. First compare the y position of the hit to the head bone positions. If outside the limits return. If inside the limits then extrapolate the vector of the bullet trajectory and a vector from hit point to head bone center and do a dot product for an equivalence test. If inside bounds you now have a vector to point at the ragdolls head to apply force and a method to apply damage decals by finding the UV coordinate of the hit point on the mesh.

1 Like

Your clips demonstrated nothing of note. Your explanation provided no procedure the OP could incorporate. Stop spamming your game. Also.what’s with the psychopath cackle after shooting somebody??

I’m using a slightly refactored version of https://assetstore.unity.com/packages/tools/integration/dynamic-raycast-system-2-0-c-jobs-123768 for this use case.

Its cheap, easy to setup and use (no extra colliders bs and related issues), quite performant, includes editor.
Cons - code is a bit messy, but that’s what you get for 15$.

Paint tris with tags, check against lookup what tag has been hit, apply damage multiplier.

Its overkill you just need a collider on the bones that you want to count as hitzone.

Its really good for testing tricky geometry, as well as skinned mesh renderers.
Colliders won’t get modified by skinning, resulting in an incorrect hits during animations (e.g. when geometry bends).

So it depends on the game / design whether its appropriate - and simple collider wasn’t good enough for my case.

Also, setting up additional colliders and layers is quite user bug-prone.

Actually, “custom collision detection” may end up being more performant in circumstances like that.

A raycast is going to query entire physical subsystem which is at least logarithmic complexity. When you already know that you hit the capsule and need to check if you hit the head that’s going to be significantly faster.

Dude nothing is cheaper than a query to a primative collider. A hit to the head is just a hit to a sphere collider.

1 Like

Its physics internal data structures rebuild that is costly in this case.

When having colliders on bones, animator modifies them constantly.
If you’ve got like 20-50 of them per opponent - it will impact performance quite a lot.
(Also, even moving them in this case will be quite costly)

As usual - it depends on numbers.

1 Like

They are set to triggers

This is our setup. 2 konvex mesh colliders for the helmet, rest is capsule and sphere. Set to trigger

I animate, rotate and translate all 100 each frame.

With colliders: 0.5781ms
Without colliders: 0.5696999ms

Keep blithering pal. Your setup has nothing to do with the OP’s question. His question was how to translate a hit on a capsule to a not already instantiated ragdoll. There is no triggers nor colliders on body parts to get hits from. Your lack of self awareness in your arrogance is cringe worthy.

If we are to nitpick, the query is provided by PhysX, meaning the call will be going through a middleman while passing C#/C++ boundary. Meaning a manual test might end up being faster, even if it is written in C#.

Triggers would be placed into the same space optimization structure as non-triggers, though.

Additionally, if you already have a hundred of them then you can’t use direct query to the collider, because you’ll lose optimization. Judging by cursory glance, physx is using BVH, aabb-based.

OP, the easiest way would be to produce a sphere collider for the head, even if it is not a part of the ragdoll. Or a replacement for that collider and check for headshot manually.

Sure but as you can see by my test even with 100 characters there is almost no change in frametime.

So it’s pretty safe, just add colliders to what your can hit and when switching to ragdoll add a little impulse force to that transforms rigidbody.

Edit, btw i also did a raycast all to the mesh collider on all 100 instances