Spawning multiple projectiles, at multiple places, which will hit multiple locations

Actually I’m now looking at creating something simpler, but that is general principle.

I have got this far right now:

void URPGPowerBase::SpawnProjectileAtLocationRadius(TSubclassOf Projectile, FHitResult Impact, float Radius, int32 ProjectileNumber)
{

	if(Impact.GetActor())
	{
		for(int32 i = 0; i < ProjectileNumber; i++)
		{
			Impact.ImpactPoint.Z = Impact.ImpactPoint.Z + 800.0f;
			Impact.ImpactPoint.X = FMath::Clamp(Impact.ImpactPoint.X + FMath::RandRange(-Radius, Radius), (Impact.ImpactPoint.X - Radius), (Impact.ImpactPoint.X + Radius)); 
			Impact.ImpactPoint.Y = FMath::Clamp(Impact.ImpactPoint.Y + FMath::RandRange(-Radius, Radius), (Impact.ImpactPoint.Y - Radius), (Impact.ImpactPoint.Y + Radius));
			//Impact.ImpactPoint.Y = Impact.ImpactPoint.Y + 500.0f;
			//Impact.ImpactPoint.X = Impact.ImpactPoint.X + 500.0f;
			FTransform SpawnTM(Impact.ImpactPoint.Rotation(), Impact.ImpactPoint);
			ARPGProjectile* proj = Cast(UGameplayStatics::BeginSpawningActorFromClass(PowerOwner, Projectile, SpawnTM));
			if (proj)
			{
				proj->Instigator = PowerOwner;
				proj->SetOwner(PowerOwner);
				Impact.ImpactPoint.Z = Impact.ImpactPoint.Z*(-1.0f);
				proj->InitVelocity(Impact.ImpactPoint);

				UGameplayStatics::FinishSpawningActor(proj, SpawnTM);
			}
		}
	}
}

What this code does it is checking if we have hit on actor.

If we have hit we move on, and modify ImpactPoint. What I want to do is to spawn projectiles above impact point in random locations in air. It’s somewhat working (it indeed spawn above, but from single point).

Then I want to these projectiles to hit in random points around ImpactPoint. It is also somewhat working, but the hit locations are definetly not what I would expect. The locations are way to spread.
I’m pretty sure my issue is the with:

proj->InitVelocity(Impact.ImpactPoint);

void ARPGProjectile::InitVelocity(FVector& ShootDirection)
{
	if (MovementComp)
	{
		MovementComp->Velocity = ShootDirection * MovementComp->Speed;
	}
}

But Honestly I don’t know now how to exactly tell projectile which point on ground it should hit.
What I need to do, in the moment where projectile is spawned in air, tell it exactly where it should go in straight line.

Any ideas ?

Is the projectile a physics body ? Is there gravity acting on it as well ?

I’m using Projectile from ShooterExample. Haven’t really change it.

I could be wrong but also to me the Impact.ImpactPoint seems to be not really the direction you want. Perhaps you want to compute the shooting direction as Impact.ImpactPoint - ProjectileSpawnPoint ?

#ImpactNormal

you are doing

proj->InitVelocity(Impact.ImpactPoint);

ImpactPoint = the FVector location of Impeact

ImpactNormal = the facing of the nearest surface to the impact

You should definitely calculate the shooting direction yourself using rotation of character / the thing that is shooting

Calculating from character weapon might actually prove tricky, because this is what I want to achieve:

Top of blue line is where the projectile spawn.

I want projectileto move along blue line to floor (in general direction).

Now I realized that projectiles just fly in all random directions all over the place.

I would probably have to calculate direction from perspective of projectile ?

#Going Straight Down

If you want to tell a projectile to go straight down from its spawn location:

FVector Destination = SpawnLoc + FVector(0,0,-10000);

Rama

Thanks. It helper and gave me good idea to where to start from! :smiley:

As it turned out later this:

 FTransform SpawnTM(Impact.ImpactPoint.Rotation(), Impact.ImpactPoint);

was part fo the issue. The rotation part. When I have set rotation to 0, and used your suggestion it finlly fly where I want it to.