Attached actors or components physics collision

Hello,

I’m struggling a lot to make a simple feature of my game work.

In my game I have a vehicle on which you can attach extra parts (tools, weapons, etc …). An extra part is an independant Actor that by default lays on the ground and that can be picked up and attached to the vehicle.

Here a simple example, you can think of the extra part as some sort of vehicle tunning to bump into zombies during an apocalypse. (the image is not from my game, it is just for the example)

What I need is that, when I’m driving my car, the bumper has to collide with other actors.
However after many days lost on this, I cannot make it work. The bumper always overlaps any other actors when my car run into them. For example, I smash the car into a wall, the bumper will overlap and only the car will collide. However the bumper collides properly with other actor when not attached to the car.

I’m attaching the bumper via C++ (but it’s the same with the AttachToActor Blueprint node)

AttachToActor(VehicleActor, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

After reviewing all this answers, I could not make it works either :

Is it even possible and how do I enable collision on the bumper (child actor) when moving the car (parent actor) ?

Found the solution !

I needed to create a UPhysicsConstraintComponent attached to the car skeleton, then apply the constraint between the bumper skeleton and the car skeleton.

Now I got my collisions perfectly working ! When I drive the car into a wall, the bumber collide and the whole car stops without the bumber passing through the wall. Hope it helps someone else.

Below the variables are :

  • BumberSkeletonComponent : the SkeletalMeshComponent belonging to the bumber actor
  • CarSkeletonComponent : the SkeletalMeshComponent belonging to the car actor
  • SocketName : the attachment socket on the car skeleton

The code :

BumberSkeletonComponent->SetWorldTransform(CarSkeletonComponent->GetSocketTransform(SocketName), false, nullptr, ETeleportType::TeleportPhysics);
UPhysicsConstraintComponent* Constraint = Cast<UPhysicsConstraintComponent>(NewObject<UPhysicsConstraintComponent>(CarActor, UPhysicsConstraintComponent::StaticClass(), FName(TEXT("Constraint"))));
Constraint->RegisterComponent();
Constraint->AttachToComponent(CarSkeletonComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale, SocketName);

Constraint->ConstraintInstance.SetAngularSwing1Motion(EAngularConstraintMotion::ACM_Locked);
Constraint->ConstraintInstance.SetAngularSwing2Motion(EAngularConstraintMotion::ACM_Locked);
Constraint->ConstraintInstance.SetAngularTwistMotion(EAngularConstraintMotion::ACM_Locked);
Constraint->ConstraintInstance.ProfileInstance.bDisableCollision = true;

Constraint->SetConstrainedComponents(BumberSkeletonComponent, NAME_None, CarSkeletonComponent, NAME_None);
1 Like