Character Physics Issues

Hey!

I’m experiencing some issues with physics/collision on Characters. Maybe this topic should fit better in Content Creation, or maybe the correct place is here in C++… I’m not sure where the solution is yet, but the problem’s related to both C++ code and I suspect Physics Assets.

Anyway, my setup:

  • Extended Character class in C++, still have the Capsule Component, but have more than a single SkeletalMeshComponent, though technically at this time only a single one of the SkeletalMeshComponents is in use.
  • The Skeletal Mesh that has been assigned to the SkeletalMeshComponent also has a PhysicsAsset assigned, which has not been created by me personally since C++ is my area of expertise, another team member created the PhysicsAsset.

The problem:

  • When I control the player (using the set-up described above), and run into an NPC with the same set-up, sometimes the NPC will respond to the bump… kind of as if he were a physics object, he’ll fly through the air a bit. This does not happen all the times, just sometimes. The same issue becomes much more easily reproducable if I swing a sword at the NPC’s legs, but since it also can happen by simply running into him I suspect the issue is not necessarily related to my implementation of weapons.

Note that I’m perfectly fine with there being collision, I can’t turn of collision completely because I don’t want to run through NPCs… I just want them to not fly through the air in response. When I turn the PhysicsAsset off, the issue also disappears, but then my collision-detection code for weapons no longer works (my code for weapon collision detection requires collision in the PhysicsAsset because I want to detect hits exactly on the meshes, and I don’t detect collision with the CapsuleComponent). So, completely getting rid of the PhysicsAsset is not an option either.

In case anyone runs into a similar issue and finds this post, I managed to fix it by setting the Collision Response to the ‘‘ECC_Pawn’’ channel on all USkeletalMeshComponents to ‘‘ECR_Overlap’’ (I guess ECR_Ignore would also work) in code. Not sure why I didn’t think of this before. Anyway, because I didn’t do this on the CapsuleComponents, it’s still possible to collide with NPCs as I intended, and my weapon collision also still works as intended, but there’s no more flying NPCs.

I noticed what I guess was the same effect when I first started playing around with UE4. I had a player controlled character with a small capsule running into an NPC with a larger capsule, and sometimes, somewhat unpredictably, the NPC would jump away while remaining upright. Very ugly. I’m still not sure what caused it, I didn’t look into it in detail.

Would I be right in thinking that by only changing the response on the ECC_Pawn channel, your character will still be colliding its skeletal mesh with other non-pawn objects in the world? I guess that’s what you want for your weapons/projectiles, but probably not for walking into static objects. And did you use the same approach in order to prevent your weapons from colliding with the capsule component?

As for still colliding with other non-pawn objects… hmm I actually didn’t really think about what I want there. Currently, yeah I guess the skeletal mesh can still collide with other objects. It shouldn’t happen often though, generally the entire body should be inside the Capsule and the Capsule should already collide earlier, therefore preventing collision with skeletal mesh components. This is also why the issue with player between NPC was much more easily reproducable for me by attacking; these animations involved the arm moving far out of the collision capsule. But yeah, I suppose in my current implementation, because I only changed the collision response to the ECC_Pawn channel, my skeletal meshes can theoretically still collide with other stuff.

As for Weapons, I’ve noticed that attaching Static Meshes to another actor (which I did to attach an equipped sword to a hand) automatically messes with the collision settings and basically makes them go through everything. Through code, I explicitly set the response of the weapon’s static mesh to ECR_Overlap to all channels, and then to ECC_PhysicsBody to ECR_Block. The Overlap response to most channels means the sword can still go through stuff and won’t make the wielder of the sword react strangely to physics, but allows my code to see when an overlap occurs and let my code handle the combat directly. The Block response to physics bodies means that u can hit movable things with ur sword and let the physics engine do its magic.

Right, yep I figured since disabling the physics asset fixed your issue, that it was probably the case that the skeletal mesh was passing outside the capsule at times, which is why I imagined you might still encounter some issues with other world geometry.

Like I said, I haven’t investigated this stuff in detail yet, however I know at some point I will need to have characters using different collision shapes depending on the type of object they’re colliding with. So, I appreciate your taking the time to explain your approach, it will be helpful when I come to deal with this. Thanks!

The engine profile for “CharacterMesh” sets the response to the “Pawn” channel to Ignore for this reason. Overlap would be fine as well. The mesh that is used by default on Characters uses this profile, but if you added others I can see why this issue came up.

Glad you got it working!

Is it possible to fix this in a blueprint only project? I’m not exactly sure what you did to solve the problem but it sounds like it involved C++