I’m in the Toon Tanks part of the Udemy course (Lesson 141), and while everything in the video works, I don’t like the fact that Projectile hit each other and get destroyed, so I want to know how to not make that happen so that they go through each other and than hit whatever is in the other side.
I tried using the function “MoveIgnoreActorAdd()” that I found on internet and wrap it inside an if() to check if the OtherActor (in the function OnHit()), is equal to AProjectile, if yes, than Ignore the Projectile like so:
void AProjectile::onHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
//UE_LOG(LogTemp, Display, TEXT("Woah"));
auto owner = GetOwner();
if(owner == nullptr) return;
auto controllerInst = owner->GetInstigatorController();
auto staticCl = UDamageType::StaticClass();
if(OtherActor->IsA(AProjectile::StaticClass())) {
this->MoveIgnoreActorAdd(OtherActor);
}
if(OtherActor && OtherActor != this && OtherActor != owner) {
UGameplayStatics::ApplyDamage(
OtherActor,
damage,
controllerInst,
this,
staticCl);
}
Destroy();
}
Of course to do this I had to change AProjectile inheritance from Actor to Pawn, but even if that is the case, it still doesn’t work, it does compile, but Projectile are still smashing with other Projectiles.
Now I’m trying to use the Function “IgnoreActorWhenMoving()” when I spawn the Projectile in BasePawn.cpp, but I’m not sure how too utilize this function, here my code:
void ABasePawn::fire()
{
DrawDebugSphere(GetWorld(), projSpawnPoint->GetComponentLocation(), 20, 12, FColor::Blue, false, 3);
auto proj = GetWorld()->SpawnActor<AProjectile>(projClass, projSpawnPoint->GetComponentLocation(), projSpawnPoint->GetComponentRotation());
proj->SetOwner(this);
proj->GetProjMesh()->IgnoreActorWhenMoving(AProjectile::StaticClass, true);
}
But I don’t know how to make the compiler understand that the Actor that the function has to get, is a generic AProjectile, so I’m currently trying some random stuff that sounds plausible.
So how do I make so that Projectiles ignore only other Projectile? Also Bonus question, Also how can I make the tank shooting delay, so that you can’t spam it, but it can only be pressed every 1 second or so.
Anyway Thanks in advance!