Override Hit-Impulse for Collision of Kinematic with Dynamic Actor

I’ve got the following situation:

A character is holding and swinging a club, which is kinematic and attached to a socket on the character’s skeleton (hand, obviously…).

When I swing at some random objects with “physics enabled” (dynamic) they get thrown away like hundreds of meters.

I will stop (or slow down) the swing animation on impact later, but first I want to know how to deal with the impulse problem.

So, I guess that there is an overridable function somewhere where I can modify the applied impulse to something more realistic. Or if that isn’t the case, maybe I shouldn’t use blocking hits but overlap events? That way I could add an impulse manually. But can I use CCD with overlap events? Because I don’t want a fast attack go right through small objects.

What I find funny is that the capsule of the character behaves totally different. When the character bumbs into something it’s almost as if he was “physics enabled”.

Can some tell me where to find the code responsible for handling character/pawn collisions with dynamic objects, so I can see how it’s done there? If I’m not terribly mistaken the character “capsule” is the one colliding and it’s also kinematic, yet it get’s blocked in it’s movement by dynamic objects as if it had finite mass.

I would very much like to know how this is done (or at least where).

I am 90% sure now I will find an answer inside CharacterMovementComponent.cpp.

But in this one’s humble opinion, all that pseudo-dynamic kinematic collision behavior could very well be implemented before CharacterMC. From PawnMC to CharacterMC there is so much new functionality, there’s room for at least one more class in the inheritance between the two.
I would find it handy, if I could have a movement component that implements the character’s “bump into stuff” behavior, but without all the character-specific rest.
Now I will probably need to do some copy pasting…

I am still working on this and would be glad if someone could help me out a little.

  • One possible solution would be, if I was able to make an actual collision (blocking) be ignored in terms of impulse generation, but still call an overridable hit-event containing the (ignored) HitResult structure. I know this is possible when working directly with NVidia PhysX, but in UE?

  • Another option could be using overlaps and no blocking collisions. But then all I get is the other actor and absolutely no info about an impact. I also can’t exclude the character holding the item from overlaps like I can with MoveIgnoreActorAdd(…) for blocking hits.

Any ideas? :confused:

I played around with collision-settings on my item-object in the editor and I’m inclined to believe there’s no way to trigger a NotifyHit without causing a simulated collision at the same time.

That means I probably won’t solve this without doing a lot of overriding.

After reading through the source code for hours, from MovementComponent to CharacterMovement, SceneComponent, Actor, PrimitiveComponent and others… I don’t even know if it’s collisions or resolving of penetration (or both?) I should be looking into.

Heeeeeelp!

6 views in 3 days… most of them probably my own…

Did you figure this out? I am also using a movement component to ensure objects block each other on collision. However, I don’t want one static mesh to send another flying away when they contact.

Perhaps the answer lies in the weight of the object…

I have been working on other parts of my game lately. But I’m rather hopeful I can solve this.

The first thing (you probably already know) is: don’t use the actor-functions for collisions etc. Use the ones on components. There you have all the hit-information, even for overlaps. CCD/Sweeping is not a problem - it works. There’s probably a little more I have figured out by now. I will post more when I get back into the problem.

EDIT:
Something else that’s relevant for me (don’t know about you) is that parenting is probably not going to work, so I have to move the club independently after the character’s animation has updated. For example, sweeping isn’t done for child-actors - they just teleport to their new transform and I don’t think there’s anything to do about it.
A minor problem with sweeping in general is that (afaik) the change in rotation of a shape is not taken into account, so the sweeps are always a little inaccurate. But that shouldn’t matter much, I guess.

Other than that, I’m not 100% sure, but I believe that what pushes objects away with way too much velocity is not actually the impact-behavior (on hit/overlap), but the “seperation” code (for existing overlaps) inside the movement-component. I will try to avoid using these components when I start working on this again, so I have full control and know exactly why things are behaving the way they are.

Man, I’m trying to do the exact same thing (swing a club) and have some control over the collision response. Sounds like we’ve gone down the same path. I was going to try to do sweeps, then use the hit information to generate my own collision response, but the inability for sweeps to take into account rotation is a big problem for me. I mean, swinging a sword or a club is mostly rotation, so without that your collision detection is going to be very wrong.

So, what I’m looking at right now is to make the weapons physically simulated, attached with constraints, and then I’m going to dig into the engine code and add the ability to modify contacts before they are resolved. Like you said, PhysX let’s you do this, but it’s just not exposed in Unreal, which is kind of dumb. Most engines I’ve used have had the ability to separate collision detection from collision response, so I’m surprise that such a popular, “advanced” engine like Unreal doesn’t have that. Anyways, my plan is to add an option to primitive components that lets hit events be reported without having an actual collision response, and behind the scenes this option will basically register a contact modification callback for the rigid body that will set the maximum impulse for the contact to 0, thus preventing a response but triggering a hit event. The only downside to this method is that it probably means the resulting hit event won’t have any information about how hard the hit was since the impulse will be 0, but I suppose I can calculate an approximation of that by calculating the relative speeds of the contact points on the two bodies.

Needless to say, this will be an endeavor, but it looks like the best option for me, especially considering how useful it could be in other scenarios where I want more control over the collision response. I’ll let you know how it goes.

Yes, please let me know!

Right now I am busy getting network replication done for what I’ve got so far, especially my animation blueprints need some more work when it comes to replicating.

I had another idea though. Maybe it’s possible to sub-divide the sweeps into smaller ones, until the delta-rotations become (more or less) neglectible.

Or, instead of using one big shape for the club/sword/whatever, maybe it’s possible to use several small shapes (with more or less uniform dimensions, like a sphere) and sweep them all individually.

I will experiment with this once I’m done with the replication stuff.

In my situation, I solved this by setting the linear and angular damping to a high value. This prevented the “impulse” or “knock-back” from sending my actor flying. This worked for me because I maintain full control over the actor’s movement, so it doesn’t need the damping to do anything other than prevent unwanted movement.

Unfortunately for me I need more control than this since I need the collision response to be partially dependent on game parameters, such as the character/weapon’s knockback power, so either modifying the contact’s impulse or generating it entirely myself is probably necessary.

Have you found out the answer? I try to create something similar to yours mechanics - swinging sword.

I tried to create constraint objects and use Angular Orientation Drive. Constantly changing its target towards mouse cursor. However if my object stops it won’t move again until any force is applied to it. Don’t know how to change that.
Here is my topic: