Hello,
i try to set up a controller → car set up, so that I can control every car in every frame with the controller.
My car is driving when it is placed without the controller.
It also works for a moving cube(with the controller), but not for cars. I do not get what I’m doing wrong.
This is part of my .h of the controller:
std::vector<AMyPawn*> car_vector;
UPROPERTY(EditAnywhere, Category = "Spawned Car")
TSubclassOf<AMyPawn> TSubClass_SpawnedCar;
This is the controller .cpp part in the “begin” function:
AMyPawn* obj = GetWorld()->SpawnActor<AMyPawn>(TSubClass_SpawnedCar,our_loc,FRotator::ZeroRotator);
car_vector.push_back(obj);
The car spawns and looks correct.
Every tick I’d like to control its movemnt:
for(std::vector<AMyPawn*>::iterator it = car_vector.begin(); it != car_vector.end(); it++)
{
FVector loc = (*it)->GetActorLocation();
FString d_string = loc.ToString();
UE_LOG(LogTemp,Log,TEXT("Car %i at position: %s"),counter,*d_string);
//Calculate movement for vehicle
(*it)->MoveForward(1.0f);
}
MoveForward is declared in the car’s cpp:
void AMyPawn::MoveForward(float Val)
{
UE_LOG(LogTemp,Log,TEXT("Throttle input set to: %f"),Val);
GetVehicleMovementComponent()->SetThrottleInput(Val);
}
Everything works until here - the ThrolleInput is set to 1 - but the car does not move. It applies possible physics (drops from the air to the ground) but does not move. What am I doing wrong?
Im glad for any help!
thanks a lot!