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):
https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/index.html
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;
Oh and by the way my RootComponent looks like this:
- CollisionSphere = CreateDefaultSubobject<USphereComponent>(TEXT(“Collision Sphere”));
- RootComponent = CollisionSphere;
I have also tried the second if statement like this to check if there is something initialized in UpdatedComponent
- if (OurMovementComponent->UpdatedComponent->GetName() == “Collision Sphere”)
This test was true. So I think there must be something assigned to UpdatedComponent.
When you have any idea what I am doing wrong or what is wrong with documentaion tell me.
PS: Sorry for the Clickbait