How can i allow my ray-cast to travel through objects?
I am using three walls to test it, When the bullet (Ray-cast) hits the first wall it will print hit. When the first wall is hit the ray-cast stops travelling and doesn’t register anything else.
How can i make it so that the first wall takes the full damage of the bullet, then the second wall will also be hit but the damage of the bullet will be halved.
After all this has been done it should print Hit,Hit,Hit in the log instead of just Hit so this can tell us that all of the three walls have been hit from one bullet.
This is my code for checking if the ray-cast hit.
FHitResult Hit;
if (Hit.Actor != NULL) {
if (Hit.GetActor()->ActorHasTag("Enemy")) {
UE_LOG(LogTemp, Warning, TEXT("Hit"))
ApplyDamage();
}
}
void AWeaponBase::ApplyDamage() {
FDamageEvent DamageEvent;
if (Hit.BoneName == TEXT("head")) {
Hit.GetActor()->TakeDamage(100, DamageEvent, Character->GetController(), this);
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), HeadshotParticle, FTransform(FVector(Hit.Location)), true);
if (Hit.BoneName != TEXT("head")) {
Hit.GetActor()->TakeDamage(WeaponConfig.HitDamage, DamageEvent, Character->GetController(), this);
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), HitParticle, FTransform(FVector(Hit.Location)), true);
}
}
}
jonimake
(jonimake)
February 26, 2017, 10:41am
2
Make a new raycast from the point where the previous raycast ended?
HavocX
(HavocX)
February 26, 2017, 8:27pm
3
… and add the object just hit to the ignore list.
jonimake
(jonimake)
February 27, 2017, 9:30am
5
Or nudge the start position a bit if detecting the exit penetration is required also.
Update:
I am using the LineTraceMultiByChannel now that i am using that my debug line is not working any ideas why
FVector StartTrace = Character->GetFirstPersonCameraComponent()->GetComponentLocation();
FVector ForwardTrace = Character->GetFirstPersonCameraComponent()->GetForwardVector();
float HipSpreadHalfAngleRadians = FMath::DegreesToRadians(InstantData.HipSpreadDegrees);
float ADSSpreadHalfAngleRadians = FMath::DegreesToRadians(InstantData.ADSSpreadDegrees);
FVector HipConeVector = FMath::VRandCone(ForwardTrace, HipSpreadHalfAngleRadians);
FVector ADSConeVector = FMath::VRandCone(ForwardTrace, ADSSpreadHalfAngleRadians);
FVector EndTraceSpread = StartTrace + HipConeVector * InstantData.WeaponRange;
FVector EndTraceAiming = StartTrace + ADSConeVector * InstantData.WeaponRange;
FCollisionQueryParams Params;
World->LineTraceSingleByChannel(Hit, StartTrace, EndTraceAiming, ECC_Visibility, Params);
World->LineTraceMultiByChannel(MultiHit, StartTrace, EndTraceAiming, ECC_Visibility, Params);
DrawDebugLine(GetWorld(), StartTrace, Hit.TraceEnd, FColor(255, 0, 0), false, 2.0, 0, 2.0);
LineTraceSingleByChannel Working
LineTraceMultiByChannel Broken