I made a custom pawn class since Paper2d only has characters (I’m aiming for a box instead of a capsule), and I got the collision and sprite parts working pretty quickly. I’ve been having a hard time getting gravity to affect it, though. I have a couple of hunches why that might be, but haven’t been able to figure it out.
Hunch 1: It seems like CharacterMovementComponent has a lot of functionality that PawnMovementComponent does not. Is PawnMovementComponent not usable? Does it need to be extended to get movement to work?
Hunch 2: I could be missing parts of the implementation. I’ve tried both PawnMovementComponent and CharacterMovementComponent, neither got gravity working with the current sweep of things that I’m doing below.
APaperPawn::APaperPawn()
{
...
//Create the collision box
UBoxComponent* BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent"));
RootComponent = BoxComponent;
BoxComponent->SetCollisionProfileName(TEXT("Pawn"));
BoxComponent->CanCharacterStepUpOn = ECB_No;
BoxComponent->bShouldUpdatePhysicsVolume = true;
BoxComponent->bCheckAsyncSceneOnMove = false;
BoxComponent->SetCanEverAffectNavigation(false);
BoxComponent->bDynamicObstacle = true;
//Set the size of the collision box
BoxComponent->InitBoxExtent(FVector(90.0f, 1.0f, 55.0f));
// Try to create the character movement component
CharacterMovement = CreateDefaultSubobject<UCharacterMovementComponent>(APaperPawn::CharacterMovementComponentName);
if (CharacterMovement)
{
CharacterMovement->UpdatedComponent = BoxComponent;
CharacterMovement->GravityScale = 1;
}
...
}
void APaperPawn::PostInitializeComponents()
{
Super::PostInitializeComponents();
if (CharacterMovement)
{
CharacterMovement->UpdateNavAgent(this);
}
if (Controller == NULL && GetNetMode() != NM_Client)
{
if (CharacterMovement && CharacterMovement->bRunPhysicsWithNoController)
{
CharacterMovement->SetDefaultMovementMode();
}
}
if (!IsPendingKill())
{
if (Sprite)
{
// force animation tick after movement component updates
if (Sprite->PrimaryComponentTick.bCanEverTick && CharacterMovement)
{
Sprite->PrimaryComponentTick.AddPrerequisite(GetCharacterMovement(), GetCharacterMovement()->PrimaryComponentTick);
}
}
}
}