[Closed] How would I get what part of a skeletal mesh I hit using c++?
I have a bullet and a player I need to be able to detect what part of the mesh I'm hitting for things like head shots.
asked Mar 11 '14 at 01:52 AM in Bug Reports
ue4-archive ♦♦ STAFF
The question has been closed Jun 21 '15 at 06:20 PM by Adam Davis for the following reason:
Problem is outdated
Video Proof of My LineTraceComponent Method
Christopher is right about the physics assets being used, and being a UE4 built in way to do the exact method you described Andrew,
I have video proof of this that I specifically made to demonstrate this!
In the video I am using pretty much the exact method I am suggesting that Lewis Use
Video, around 2:33
Starting around 2:33
I walk a little skeleton up to a big skeleton who is playing an idle anim that causes his hand to be at times in range of just the very tip of the little skeleton's sword
I have skeleton swing a bunch of times, well within the collision capsule, and it misses!
and then right when the idle anim is playing and the big skeleton's hand comes juuuuuust in range of the sword tip, THEN the hand goes flying and the skeleton registers a hit!
The hand going flying is proof I accessed that exact bone and applied an impulse.
Note the Big Skeleton Never Moves
The big skeleton neeever moves, it is just the idle animation and the bone movements that are determining when the skeleton is in range of the sword tip!
This video is pretty much the code and method I mention in this UDN post.
By the Way
I thoroughly enjoyed your additional explanation Andrew
and thanks for the pics and taking the time!
but I do feel that Christopher is right, and the Physics asset is being used with LineTraceComponent, and not just the whole-body mesh.
Great clarifications for the Community!
Rama's solution is pretty solid. It works especially well if you wanted highly-accurate collision detection, as it is tracing against the mesh itself (not against hand placed collision boxes like my suggestion). It does, however, make it a bit difficult to detect exactly where the bullet hit (you would have to check the name of the bone against a list of compatible target bones, a messy and inaccurate process, especially with an abundance of facial joints or sloppy weighting). This isn't a problem at all if you have multiple skeletal mesh components making up the body, but I'm going to assume that you don't.
A more tried-and-tested solution is to attach a number of small 'collision boxes' to important parts of your character. I'm going to use Counter Strike as an example, a popular networked FPS in case you are unfamiliar with it.
This is obviously less accurate than Rama's solution of tracing against the mesh directly, but it does offer some advantages you may or may not be interested in:
By no means are collision boxes the only way to do these things. You could do them with mesh tracing too, if you really wanted, it would just require a different implementation.
Lastly, here is the article that I sourced (pun intended) the second image from. It is a worthwhile read if networked games interest you, even if you don't use collision boxes for your implementation.
I talked a lot about the upsides of the collision box system. I thought I should mention some of the downsides, so you had the complete picture:
These can both be overcome with varying implementations, but I figured I would put them here for completion sake.
//if tracing other's skel mesh you can use OtherCharacter->Mesh->LineTrace....
//Rest of HitResult Info Provided from Above Function
Follow this question
Once you sign in you will be able to subscribe for any updates here