2D sprite collision : Multiple hitbox

Hello,

I set multiple hitboxes per sprite frame and I would like to be able to manage the physics with one of them and only get the overlap triggers with the others.
The idea is to see if I can make a 2D Fighter game in EU4 and I need to be able to manage my collision frame by frame.

Thanks for the help,

rXp

You can set each box to trigger collisions or to trigger overlaps with their collision profiles. When you spawn the hitbox components you can set their collision rules like the following:

For collision and physics:

    //activating physics and collision for this component
    HitboxComp->bShouldUpdatePhysicsVolume = true;

    //setting collision response type
    HitboxComp->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

    //setting a collision profile; each profile has default behaviors defined per channel
    HitboxComp->SetCollisionProfileName(UCollisionProfile::BlockAllDynamic_ProfileName);


    //you can override individual channel responses within your existing profile, or set specific responses for every
    //available channel in your game

    //this strips any preset collision responses and sets the component to ignore all
    HitboxComp->BodyInstance.SetResponseToAllChannels(ECR_Ignore);

    //you can set individual response types for the channels you want; ECR_Overlap, ECR_Block, or ECR_Ignore
    //in this case all are set to block (collide)
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_WorldStatic, ECR_Block);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_WorldDynamic, ECR_Block);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_Pawn, ECR_Block);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_PhysicsBody, ECR_Block);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_Vehicle, ECR_Block);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_Destructible, ECR_Block);

For overlap events:

    HitboxComp->bGenerateOverlapEvents = true;
    HitboxComp->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryOnly);

    //define the collision profile for this component
    HitboxComp->SetCollisionProfileName(UCollisionProfile::BlockAllDynamic_ProfileName);

    //set response to all existing channels
    HitboxComp->BodyInstance.SetResponseToAllChannels(ECR_Ignore);

    //set response to individual channels; not all channels have to have the same response
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_WorldStatic, ECR_Ignore);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_Pawn, ECR_Overlap);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_PhysicsBody, ECR_Overlap);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_Vehicle, ECR_Overlap);
    HitboxComp->BodyInstance.SetResponseToChannel(ECC_Destructible, ECR_Overlap);

You can also set these values in the editor within the details panel of your object, under Collision and the Collision Presets panel.

In your case, I would define a custom collision profile for your overlap hitboxes and one for your physics-enabled hitbox and assign them as needed.

For more details see:

Default collision channels and response types are defined in ‘Runtime/Engine/Classes/Engine/EngineTypes.h’; see lines 553 and 743.

UCollisionProfiles are defined in ‘Runtime/Engine/Classes/Engine/CollisionProfile.h’

Thank you about that seems to be a good way to do it but now my issue is that I don’t use 3D hitboxes.

As you can see in my screenshot I set the different collision boxes in each frame of an animation. I have for this animation 4 boxes and only one that will keep my character on the ground.
But I can see only one collisions presets that apply to all my hitboxes.

So now I think I should do this only in C++ but this means I should get all the frames of all the animations and set the correct collision presets to them ?

Am I getting something wrong ?

This may be a limitation with the Paper2D setup and how they’ve built collisions into it.

What you may what to do is build your collisions objects as UStaticMeshComponents and tie their relative positions to your animation update (annoying, I know), rather than utilizing the collisions within your sprite component.

Or, you can dig into the Paper2D plugin and see how they are actually building and referencing the individual hit boxes. You may be able to access them as individual components and then assign their collision presets/channels programmatically. Or modify Paper2D itself.

Or you could build your physics object as a separate UStaticMeshComponent, and use all the hitboxes as overlaps (or vice versa). That way at least you only have to build one/some of the components as 3D meshes.

Have you tried setting the collision preset and then selecting a different hit box? See if maybe it’s only showing the collision data for one component at a time

It does not :frowning:
It’s one preset for all collision boxes for the frame.
I could overlap everything and make my own mini-physic engine but I really don’t see the point in using UE4 in that case.

Well I guess I have to dig dipper :confused:

That’s too bad.

I think your best bet will be to use a UStaticMesh for collisions/physics outside your sprite and use the sprite hitboxes for the overlaps. You’ll just need to make sure you update the UStaticMeshComponent’s relative position as the sprite animates; that shouldn’t be too bad.

Or start digging into Paper2D.

Good luck.

Hi! I wanted to know if you found out how to access or manage the custom collisions you drew for your sprites. It would be amazing if you let me know

Hi! I kinda found a solution, you have to download the source code of the engine. Modify it so it will take into account one set of collision boxes per frame. Then you should also add a way to differentiate the hit box hurtbox throwbox etc so you know what collides with what.
I’m sorry there is no easy implementation with ue.

Thanks, doesn’t sound easy but gives me a lot of ideas!