Download

Issue with gravity on a custom pawn

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: Most of my code has been copied from APaperCharacter and ACharacter, but it seems like there are some things exposed to an ACharacter-based blueprint in the editor that don’t exist in ACharacter (or APawn, since I would have it as well.) I’m interested in where they come from.

One of the sets of options in question:
Capture.JPG

From running a search in Character.h, the string “Character Movement:” doesn’t appear anywhere. Is there code somewhere that I’m not finding?

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);
			}
		}
	}
}