【发布时间】:2020-06-27 22:33:08
【问题描述】:
我先用Blueprints 做一个简单的桨游戏,然后用C++ 做。
这是我的代码基础:
void APaddleGameGameMode::SpawnBall()
{
UWorld *world = GetWorld();
if (world)
{
Ref_GameBall = world->SpawnActorDeferred<APaddleGameBall>(APaddleGameBall::StaticClass(), FTransform(FRotator::ZeroRotator, FVector::ZeroVector, FVector::OneVector), NULL, NULL, ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding);
if (Ref_GameBall) world->GetTimerManager().SetTimer(DelayBallMovement, this, &APaddleGameGameMode::SetVelocity, 0.2f);
}
}
void APaddleGameGameMode::SetVelocity()
{
if(Ref_GameBall) Ref_GameBall->ProjectileMovement->Velocity = FVector(Direction * Speed, 0.f, 0.f).RotateAngleAxis(FMath::RandRange(-45.f, 45.f), FVector(0.f, 1.f, 0.f));
Ref_GameBall->ProjectileMovement->Activate();
}
void APaddleGameGameMode::UpdateScore(bool bIsAI)
{
UWorld *world = GetWorld();
if (bIsAI)
{
SPScore++;
Direction = 1.f;
}
else
{
FPScore++;
Direction = -1.f;
}
if (world) world->GetTimerManager().SetTimer(DelaySpawningBall, this, &APaddleGameGameMode::SpawnBall, 1.f);
}
一开始它工作正常,最初的 spawnin:球被生成并且它需要移动;但它在第二次生成时不起作用,我不明白为什么,生成了球但它没有移动。
谁能给我解释一下并帮我解决?
谢谢。
【问题讨论】:
标签: c++ unreal-engine4 unreal-blueprint