I’ve been given the task to create a 2D platformer in UE5 and C++, use of blueprints is really limited. I’m attempting to use a 2D pawn and move it using custom movement as the character controller isn’t suited for our needs.
The issue lies when the character moves, it will be pulled back toward the direction it came, this happens both during jumping and while moving.
Please find the issue here Issue
UCLASS()
class GA2BCODEPROJ_API ACharacter2D : public APawn
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* BoomArm;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* Camera;
public:
// Sets default values for this pawn's properties
ACharacter2D();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
UPaperSpriteComponent* PlayerSprite;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
void MoveRight(float value);
void Jump();
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
private:
FVector MovementDirection;
UPROPERTY(EditAnywhere, Category = "Movement")
float MovementSpeed = 500.f;
};
void ACharacter2D::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (!MovementDirection.IsZero()) {
const FVector NewLocation = GetActorLocation() + (MovementDirection * DeltaTime * MovementSpeed);
SetActorLocation(NewLocation);
UE_LOG(LogTemp, Warning, TEXT("Adjusting Movement"))
}
}
// Called to bind functionality to input
void ACharacter2D::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
check(PlayerInputComponent);
PlayerInputComponent->BindAxis("MoveRight", this, &ACharacter2D::MoveRight);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter2D::Jump);
}
void ACharacter2D::MoveRight(float value)
{
MovementDirection.Y = value;
UE_LOG(LogTemp, Warning, TEXT(“Adjusting Value”))
}
void ACharacter2D::Jump()
{
PlayerSprite->AddImpulse(FVector(0, 0, 500.f)1PlayerSprite->GetMass());
}
Blockquote