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 ?