Problem
I have created a pawn wich is controlled by a custom player controller. At the moment I move the pawn like this:
FVector NewLocation = GetActorLocation();
NewLocation += GetActorForwardVector() * (SpeedLvL * Speed) * DeltaTime;
SetActorLocation(NewLocation);
This part is exectuted every Tick. But when I move my pawn like this it obviously “ignors” collision.
So I’ve implemeted a PawnMovementComponent by following this documentation (Step 2 & 3):
In the documenation the Input is passed to the MovementComponent like this:
void ACollidingPawn::MoveForward(float AxisValue)
{
if (OurMovementComponent && (OurMovementComponent->UpdatedComponent == RootComponent))
{
OurMovementComponent->AddInputVector(GetActorForwardVector() * AxisValue);
}
}
After I’ve followed this steps and wanted to test my code the if statement doesn’t become true. Splitting it into:
void ACollidingPawn::MoveForward(float AxisValue)
{
if (OurMovementComponent)
{
GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, "Step 1 done");
if (OurMovementComponent->UpdatedComponent == RootComponent)
{
GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, "Step 2 done");
OurMovementComponent->AddInputVector(GetActorForwardVector() * AxisValue);
}
}
}
Showed me that the second if (OurMovementComponent->UpdatedComponent) is not == the RootComponet, so this part fails.
I initialize the OurMovementComponent in the constructor like this:
OurMovementComponent = CreateDefaultSubobject<UCollidingPawnMovementComponent>(TEXT("CustomMovementComponent"));
OurMovementComponent->UpdatedComponent = RootComponent;
When you have any idea what I am doing wrong or what is wrong with documentaion tell me.
PS: Sorry for the Clickbait