i have a line trace and i want to apply damage to it but every time i do it i get a error “type name not allowed”
on aaicharacter and horde character
horde .cpp
horde character .cpp
void AHordeCharacter::OnFire()
{
FHitResult hit;
FVector start= FP_Gun->GetForwardVector();
FVector End = start + (FP_Gun->GetForwardVector()* 700.f);
FCollisionQueryParams CollisionParams;
FVector Start= FP_Gun->GetComponentLocation();
DrawDebugLine(GetWorld(), Start, End, FColor::Green,true,2.f,false,4.f);
GetWorld()->LineTraceSingleByChannel(hit, start, End, ECC_WorldDynamic, CollisionParams);
UGameplayStatics::ApplyDamage(AAI_Character, 10.f, AHordeCharacter, false, false);
}
I personally would create a function in the character you try to apply damage to called, cast to that function when you hit the character and apply the damage yourself.
Similar to this:
horde character:
void AHordeCharacter::OnFire()
{
AAICharacter* character = Cast<AAICharacter>(hit.GetActor());
//linetrace stuff
if(hit.GetActor)
{
character->Damage(damageamount);
}
}
AICharacter:
void AAiCharacter::Damage(damageamount)
{
health = health - damageamount;
}
On the other hand the underscore in the “AAI_Character” could be an issue, but I’m not sure about that.
i keep getting a error for hit is undefined
try adding “ForceInit” to the Fhitresults.
Like this: FHitResults hit(ForceInit);
it still says it, i am suppose to be including a file
maybe this link will help in finding the issue?
How to use linetrace in c++