I have a player character which picks up a bowling ball and then is supposed to throw the ball. I tried to set the ball to use a projectile movement component that would use the power variable from the Player Character, but it never works.
Bowler Character getting power and spawning the ball:
void ABowler::OnBeginPress()
{
if (bHasBall)
{
BeginTime = FApp::GetCurrentTime();
}
}
void ABowler::OnEndPress()
{
if (bHasBall)
{
EndTime = FApp::GetCurrentTime();
float total = EndTime - BeginTime;
Power = total * 500;
Bowl();
}
}
void ABowler::Bowl()
{
bHasBall = false;
UWorld* const World = GetWorld();
if (World)
{
//Set Spawnlocation, rotation, and parameters here...
ABowlingBall* const SpawnedBall =World->SpawnActor<ABowlingBall> (BallClass, SpawnLocation, SpawnRotation, SpawnParams);
}
}
Constructor for the BowlingBall which is spawned:
const UWorld* World = GetWorld();
if (World)
{
ABowler* MyCharacter = Cast<ABowler>(UGameplayStatics::GetPlayerPawn(this, 0));
if (MyCharacter)
{
BallPower = MyCharacter->Power;
}
}
ProjectileMovement = PCIP.CreateDefaultSubobject<UProjectileMovementComponent>(this, TEXT("ProjectileComp"));
ProjectileMovement->InitialSpeed = BallPower;
//Other Projectile Movement Properties...
}
Ball Power does have a value as you can see here:
But, when the ball spawns, it just drops to the ground like the initial speed is 0. When I set it to a specific number, like 1000, it works fine.
Thanks,
Martin.