I’m learning to make a weapon system. There is a feature in that system which is the damage applied to the character should be different when hitting different part of the character. I tried to implement this function by using physics material, however, the line trace I use can’t get the physics material, I wonder why this happened?
Here is the line trace I use:
FHitResult AFPWeaponBase::CalculateLineTrace(AFPCharacter* Player)
{
FHitResult HitResult;
if (Player)
{
UFPWeaponSystemComponent* WeaponSystem = UFPWeaponSystemComponent::GetWeaponSystemComponent(Player);
FVector Start = Player->GetCamera()->GetComponentLocation();
FVector End = Player->GetCamera()->GetComponentRotation().Vector() * ShotRange + Start;
if (WeaponSystem && !WeaponSystem->GetIsAiming())
{
End.X += FMath::FRandRange(-BulletSpread, BulletSpread);
End.Y += FMath::FRandRange(-BulletSpread, BulletSpread);
End.Z += FMath::FRandRange(-BulletSpread, BulletSpread);
}
FCollisionObjectQueryParams ObjectParams;
ObjectParams.AddObjectTypesToQuery(ECC_WorldStatic);
ObjectParams.AddObjectTypesToQuery(ECC_WorldDynamic);
ObjectParams.AddObjectTypesToQuery(ECC_Pawn);
FCollisionQueryParams Params;
Params.AddIgnoredActor(Player);
GetWorld()->LineTraceSingleByObjectType(HitResult, Start, End, ObjectParams, Params);
// DEBUG: Remove this code later.
FColor Color = HitResult.Actor.IsValid() ? FColor::Green : FColor::Red;
DrawDebugLine(GetWorld(), Start, End, Color, false, 3.0f);
return HitResult;
}
return HitResult;
}
After debugging I’m sure that this line trace hit the character I want to hit, but it just can’t get the physics material of the character.
I’ve set the phsics mesh like below
and I’ve set the character collision like this
Just the original settings of character, I’ve tried to change the Collision set , but it doesn’t help, I still can’t get the physics material, anybody konws how to solve this problem?