I am trying to apply damage to an enemy through raycasting but I don’t know-how. Any help is appreciated.
I actually haven’t done this yet, not in c++ anyways but I found this forum you can check out!
If this helps could you please upvote my question @ IOnlineSession::FindSessions() sends weird warning - Multiplayer & Networking - Epic Developer Community Forums
It would help a ton!
I actually did the same as the link you posted but for some reason, it ignores the actor. The message is always blue but if I get rid of bombercast it works just fine.
ABomberCharachter * bombercast = Cast(OutHit.GetActor());
GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, CollisionParams);
if (bombercast) {
if (GEngine) {
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Red, FString::Printf(TEXT("Impact Point: %s"), *OutHit.ImpactPoint.ToString()));
}
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Blue, FString::Printf(TEXT("Impact Point: %s"), *OutHit.ImpactPoint.ToString()));
}
It looks like you have an error in order in which youre doing things (that or the formatting mangled it out of order), but you also have an error calling Cast:
GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, CollisionParams); //Do the lineTrace first
ABomberCharachter * bombercast = Cast<ABomberCharachter>(OutHit.GetActor()); //then cast the actor to your class
Still not working. Maybe I am casting it wrong. Maybe something about .h file?
if (GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, CollisionParams)) {
ABomberCharachter * bombercast = Cast<ABomberCharachter>(OutHit.GetActor());
if (bombercast) {
if (GEngine) {
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Red, FString::Printf(TEXT("Impact Point: %s"), *OutHit.ImpactPoint.ToString()));
}
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Blue, FString::Printf(TEXT("Impact Point: %s"), *OutHit.ImpactPoint.ToString()));
}
}
Unlikely, my next bet is that the OutHit.Actor is null, or the cast outright fails because you’re not hitting ABomberCharachter after all. If you didnt change Collision Preset in your blueprint, the default Pawn and Character presets dont respond to Visibility trace. Try tracing with ECC_Camera (they respond to that by default), or changing collision responses on your actor youre trying to hit.
Thanks so much. Seriously I have tried for a week never thought of this. God bless you.