How to make Projectiles ignore other Projectiles? (Toon Tanks Lesson 141)

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!

First, to get projectiles to ignore other projectiles, I think you need a custom collision setup to tell it to not collide with projectile types. Not sure exactly how you go about that off the top of my head but it would be on the projectile itself.

The non-spamming of fire. There’s a few ways to deal with this. One approach (depending on your input system of course so assuming new input here), use either the started or triggered input for the fire. Next, set up a bool called CanFire or something, true as default.

On triggered fire, check CanFire - yes? then fire, set the bool to false and then start a timer with fire delay. This lets the player hold the button down. If you use Started, only when they click fire does it check and fire. Depends on the mechanism you want.

I hope this helps.

FYI - this works pretty much for any fire mechanism and even AI-related players can use the same mechanism.

Privacy & Terms