2016-04-29 354 views
0

AWheeledVehicle運動,我試圖將我的車輛(AWheeledVehicle)向前移動。我正確地參考了正確的車輛,但仍然不動。 不知道我在做什麼錯。使用虛幻引擎4的C++

以下附件是我的車和控制器類

AAIWheeledVehicle

AAIWheeledVehicle::AAIWheeledVehicle(){ 
    AIControllerClass = AMyAIVehicleController::StaticClass(); 
} 

AMyAIVehicleController在UE4

void AMyAIVehicleController::Possess(APawn *pawn){ 
    Super::Possess(pawn); 
    //FVector location2 = pawn->GetActorLocation(); // -11310, 8910, 0 

    // initialize location of target point 
    location.X = -9620.0f; 
    location.Y = 8910.0f; 
    location.Z = 0.0f; 

    scaleValue = 1.0f; 

    target = GetWorld()->SpawnActor<ATargetPoint>(location, FRotator::ZeroRotator); 
    target->SetActorLocation(location); 

    // get AI vehicle reference 
    vehicle = Cast<AWheeledVehicle>(pawn); 
    // add forward movement to vehicle, scale = 1 
    vehicle->AddMovementInput(GetActorForwardVector(), scaleValue); 

    //vehicle->GetVehicleMovement()->Velocity.X = 1.0f; 
    //vehicle->GetVehicleMovement()->SetThrottleInput(1.0f); 
    //vehicle->GetVehicleMovement()->SetSteeringInput(1.0f); 
    //vehicle->GetVehicleMovement()->SetHandbrakeInput(false); 

    // set rotaion of vehicle to rotation of the target point 
    vehicle->SetActorRotation(target->GetActorRotation()); 
} 

回答

-1

車輛設置是棘手的。它有幾個運動部件一起工作。確保您的初始車輛設置正常,否則無論涉及的代碼如何,它都可能無法移動。 (順便說一句,代碼看起來不錯,但我建議在藍圖中進行測試以驗證所有設置是否正確)

我在我的頻道上製作了關於UE4中車輛設置的視頻,這可能會解決您的問題。通過並確保設置相同,因爲無論您使用的是C++還是藍圖,都需要執行此操作。以下是鏈接:

UE4 - How to Make Vehicles