Hi
I want to get work my flying APawn wich is controlled with my own input handling.
So it is flying already, but I want it to slide along the walls and floor like DefaultPawn does. Fly example doesn’t help with it.
With ACharacter I was able to apply movements to MovementComponent (although I wasn’t able to make it fly), but APawn does not have one, so temporary I using FVector Movement to apply location offset:
void AMyPawn::Tick(float deltaTime)
{
Super::Tick(deltaTime);
AddActorLocalOffset(Movement,true);
Movement = FVector::ZeroVector;
}
Obviously it doesn’t slide, it just moving until collision happens.
I am not sure does MovementComponent handles a collision reaction to achieve sliding. If it’s true, please give me a hint what methods to override and how it integrate MovementComponent into my AMyPawn.
Let me summarize what I want to achieve:
I want to make my pawn fly with collision and sliding over static objects (C++)
Thanks for any help
P.S. Sorry my poor English
Ok
I found solution:
// AMyPawn.h
TSubobjectPtr<UFloatingPawnMovement> MovementComponent;
virtual class UPawnMovementComponent* GetMovementComponent() const OVERRIDE
{
return MovementComponent;
}
// AMyPawn.cpp
AMyPawn::AMyPawn(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
Capsule = PCIP.CreateAbstractDefaultSubobject<UStaticMeshComponent>(this, TEXT("Capsule"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMesh(TEXT("StaticMesh'/Game/Shapes/Shape_NarrowCapsule.Shape_NarrowCapsule'"));
Capsule->SetStaticMesh(StaticMesh.Object);
RootComponent = Capsule;
Capsule->SetCollisionObjectType(ECollisionChannel::ECC_Pawn);
MovementComponent = PCIP.CreateDefaultSubobject<UFloatingPawnMovement>(this, TEXT("Movement"));
MovementComponent->UpdatedComponent = Capsule;
}
void AMyPawn::AddMove(FVector move)
{
FRotator rot(PC->PlayerCameraManager->GetCameraRotation());
this->AddMovementInput(rot.RotateVector(move), 10);
}
And Tick overriding is not necessary.
But there is some non sliding walls glitch now. But it’s another story