Hi!
I’m trying to implement a ricochet mechanic in c++ and i’m following this guide A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums
My project:
I started a default “First person” template and changed the code from OnFire located in the default character with the following lines
void ATest_RicochetCharacter::OnFire()
{
FHitResult Hit, HitBounce;
//start a bit forward from camera
FVector Start = FirstPersonCameraComponent->GetComponentLocation() + FirstPersonCameraComponent->GetForwardVector() * 150;
FVector End = FirstPersonCameraComponent->GetComponentLocation() + FirstPersonCameraComponent->GetForwardVector() * 2150;
GetWorld()->LineTraceSingleByChannel(Hit, Start, End,ECollisionChannel::ECC_WorldStatic ,FCollisionQueryParams::DefaultQueryParam);
//if it hits = ricochet and draw debug line from start to hit location
if (Hit.bBlockingHit) {
DrawDebugLine(GetWorld(), Hit.TraceStart, Hit.Location, FColor::, false, 5.0f);
GetWorld()->LineTraceSingleByChannel(HitBounce, Hit.ImpactPoint + Hit.Normal, (End).MirrorByVector(Hit.ImpactNormal), ECollisionChannel::ECC_WorldStatic,FCollisionQueryParams::DefaultQueryParam);
//if it hits = draw debug line from hitbounce start to hitbounce location
if (HitBounce.bBlockingHit) {
DrawDebugLine(GetWorld(), HitBounce.TraceStart, HitBounce.Location, FColor::Green, false, 5.0f);
}
else {
DrawDebugLine(GetWorld(), HitBounce.TraceStart, HitBounce.TraceEnd, FColor::Black, false, 5.0f);
}
}
else {
DrawDebugLine(GetWorld(), Hit.TraceStart, Hit.TraceEnd, FColor::Black, false, 5.0f);
}
}
This are the results i got:
Seems to work
but I aim up a little bit
second image with zoom
seems to work on the side
but i aim a little to the right and this happens
it looks like more angle = worst result
Any comments would be appreciated