在c ++中的AWheeledVehicle运动

时间:2016-04-29 21:52:07

标签: c++ unreal-engine4

使用虚幻引擎4,我试图向前移动我的车辆(AWheeledVehicle)。我正确地引用了正确的车辆,但它仍然不会移动。 不知道我做错了什么。

下面是我的车辆和控制器类

AAIWheeledVehicle

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

AMyAIVehicleController

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 个答案:

答案 0 :(得分:-1)

UE4中的车辆设置非常棘手。它有一些可以协同工作的移动部件。确保您的初始车辆设置正常,否则无论涉及哪些代码,它都可能无法移动。 (顺便说一句,代码看起来很好,但我建议在蓝图中进行测试以验证设置是否正确)

我在我的频道上制作了关于UE4中车辆设置的视频,这可能会解决您的问题。通过并确保设置是相同的,因为无论您使用的是C ++还是蓝图,都需要这样做。这是链接:

UE4 - How to Make Vehicles