Pawn Movement component not moving

I have tried to set up some code that makes the pawn move up when the jump function is called. When the function is called however , there is no movement , and I can tell the function is definitely getting called through the debug message.

The code is:

#include "ClientMessage.h"
#include "MyPawn.h"


AMyPawn::AMyPawn(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Root")
	TSubobjectPtr<UStaticMesh> TouchCapsule = PCIP.CreateDefaultSubobject<UStaticMesh>(this, TEXT("Body"));
	
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Root")
	TSubobjectPtr<UPawnMovementComponent> myMovement = PCIP.CreateDefaultSubobject<UPawnMovementComponent>(this, "movement component", false);
	
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Root")
	TSubobjectPtr<USphereComponent> CollisionComponent = PCIP.CreateDefaultSubobject<USphereComponent>(this, "collision component");
	CollisionComponent->bShouldUpdatePhysicsVolume = true;
	RootComponent = CollisionComponent;
	myMovement->UpdatedComponent = CollisionComponent;
	

}
void AMyPawn::jump()
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("jump"));
	AddMovementInput(FVector::UpVector, jumpHeight);
}

How would i set the acceleration in a tick() function?

check out:
UFloatingPawnMovement::TickComponent
which calls the function:
UFloatingPawnMovement::ApplyControlInputToVelocity

ApplyControlInputToVelocity clamps the movementInput between -1 and 1
then it applies acceleration by multiplying an accelerationConstant against that clamped movementInput and delta time, then adding all that to the velocity, then clamping by max speed.

Velocity += Acceleration * DeltaTime * MovementInputClamped;

the reason PawnMovementComponent doesn’t have this stuff built in is because its a very generic class. your custom pawn could be anything from a dancing human to a stationary crane to a motorcycle, and the joysticks need to be mapped to different variables for each of these.

1 Like

The velocity of the UPawnMovementComponent is private , so that returns an error.

set it from inside yourMovmentComponent within TickComponent()

check out FloatingPawnMovement.cpp, it is a simple example of a pawnMovementComponent, so copy some of their code into your child class of pawnMovementComponent to get some simple movement.

it looks like instead of AddMovementInput you should use SetActorLocation like in https://docs.unrealengine.com/latest/INT/Programming/Tutorials/PlayerInput/index.html

have you set this AutoPossessPlayer = EAutoReceiveInput::Player0; ?
also do you have a PawnMovementComponent implemented ?

follow this tutorial
https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/2/

yes I set AutoPossessPlayer = EAutoReceiveInput::Player0; in the constructor

as for the PawnMovementComponent - I did not implement that, actually I tried, but something was not compiled, i’m a newby to C++, my whole life i’ve been working with .net and c# :slight_smile:

In your pawn movement component you have to override
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
Method its all in the tutorial