Thanks for responding.
My pawn doesnt inherit from character (atleast I dont think so). The reason why I m not using just a character is because I would rather not have some of the things that are in the character movement because they conflict with some functionality I want to implement (specifically strafe jumping/ air strafing). I have managed to implement strafejumping in c++ and blueprint but only using Character classes. However it doesnt quite feel right, and things like friction and speed mess up. I was under the impression that I can have a normal pawn, and then attach a pawn movement component to it and be able to code simple movement controls (like addmovementinput() etc).
I checked and no warnings in the editor, so I dont think its being set to static.
Here are my classes.
my pawns .h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Components/BoxComponent.h"
#include "DellPawn.generated.h"
class UDellPawnMoveComp;
class UCameraComponent;
UCLASS()
class DELLMOD_API ADellPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ADellPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
/** Called when the character changes controller or gets a new one */
virtual void PossessedBy(AController* NewController);
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
AController* Controller;
public:
/** Character's movement component */
UPROPERTY(Category = Character, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
UDellPawnMoveComp* MovementComponent;
//Pawns Collision
UPROPERTY(Category = Character, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
UBoxComponent* PawnCollision;
//Pawns Forward Reference
USceneComponent* PawnForward;
//Pawns Camera
UCameraComponent* PawnCamera;
/* X is forward [W] and back [S] (1.0 to -1.0) and Y is right [D] and left [A] (1.0 to - 1.0) */
UPROPERTY(Category = Input, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
FVector2D MovementInput;
/* Stores relational (to last frame) mouse position */
FVector2D MouseVelocity;
/** Handles moving forward/backward */
void MoveForward(float Value);
/** Handles strafing movement, left and right */
void MoveRight(float Value);
/** Mouse movement input callbacks */
void MouseX(float Value);
void MouseY(float Value);
void StartJump();
void StopJump();
FVector CurrentVelocity;
};
my pawn’s pawnmovementcomponent .h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PawnMovementComponent.h"
#include "DellPawnMoveComp.generated.h"
class ADellPawn;
/**
*
*/
UCLASS()
class DELLMOD_API UDellPawnMoveComp : public UPawnMovementComponent
{
GENERATED_BODY()
public:
/** Character this belongs to */
ADellPawn* Player;
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
FVector2D WishMove;
void QueueJump();
};
my pawn’s pawnmovementcomponent .cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "DellPawnMoveComp.h"
#include "DellPawn.h"
#include "Engine.h"
class ADellPawn;
void UDellPawnMoveComp::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
// Grab the input from the player
//WishMove = Player->ConsumeMovementInput();
FVector Invec = FVector(1000, 3000, 0);
AddInputVector(Invec, true);
//Player->AddMovementInput(Invec, 1, true);
//PawnOwner->AddMovementInput(PawnOwner->GetActorForwardVector(), 1, true);
//Velocity.X = 4000.f;
//UpdateComponentVelocity();
GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::White, " , " + FString::SanitizeFloat(52221.f));
}
void UDellPawnMoveComp::QueueJump()
{
//Velocity.Z = 500.f;
}
my pawn’s .cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "DellPawn.h"
#include "Engine.h"
#include "DellPawnMoveComp.h"
#include "Components/BoxComponent.h"
// Sets default values
ADellPawn::ADellPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//Create Pawns Collision
PawnCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("Pawns Collision"));
PawnCollision->InitBoxExtent(FVector(30.f, 30.f, 62.f));
//Set Collision As Root
RootComponent = PawnCollision;
//Create Reference To Players Forward Vector
PawnForward = CreateDefaultSubobject<USceneComponent>(TEXT("Pawns Forward Reference"));
if (PawnForward) {
PawnForward->AttachTo(PawnCollision); //Attach Forward Reference To Collision
}
PawnCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Pawn Camera"));
if (PawnCamera) {
PawnCamera->SetRelativeLocation(FVector(0.f, 0.f, 62.f - 4.f));
}
MovementComponent = CreateDefaultSubobject<UDellPawnMoveComp>(TEXT("Pawn Movement Component"));
MovementComponent->UpdatedComponent = PawnCollision;
// Take control of the default player
AutoPossessPlayer = EAutoReceiveInput::Player0;
}
// Called when the game starts or when spawned
void ADellPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ADellPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
// SetActorLocation(NewLocation);
}
// Called to bind functionality to input
void ADellPawn::SetupPlayerInputComponent(UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
check(InputComponent);
// Set up movement
InputComponent->BindAxis("ForwardMovement", this, &ADellPawn::MoveForward);
InputComponent->BindAxis("RightMovement", this, &ADellPawn::MoveRight);
InputComponent->BindAction("Jump", IE_Pressed, this, &ADellPawn::StartJump);
InputComponent->BindAction("Jump", IE_Released, this, &ADellPawn::StopJump);
// Set up mouse inputs
InputComponent->BindAxis("MouseControlX", this, &ADellPawn::MouseX);
InputComponent->BindAxis("MouseControlY", this, &ADellPawn::MouseY);
}
void ADellPawn::PossessedBy(AController* NewController)
{
// Assign the new controller
Controller = NewController;
}
void ADellPawn::MoveForward(float AxisValue)
{
if (AxisValue != 0.0f)
CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100;
//GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Red, " , " + FString::SanitizeFloat(1555555551.f));
//AddMovementInput(GetActorForwardVector(), Value, true);
}
void ADellPawn::MoveRight(float AxisValue)
{
if (AxisValue != 0.0f)
//CurrentVelocity.Y = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100;
AddMovementInput(GetActorRightVector(), AxisValue, true);
}
void ADellPawn::MouseX(float Value)
{
FVector v(0.f, 0, Value);
PawnCamera->AddWorldRotation(FQuat::MakeFromEuler(v));
}
void ADellPawn::MouseY(float Value)
{
FVector v(0, -Value, 0);
PawnCamera->AddLocalRotation(FQuat::MakeFromEuler(v));
}
void ADellPawn::StartJump()
{
//MovementComponent->AddInputVector((FVector(0, 0, 700.f)), true);
MovementComponent->Velocity.Z = 600.f;
//GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::White, " , " + FString::SanitizeFloat(11.f));
}
void ADellPawn::StopJump()
{
//MovementComponent->Velocity.Z = 600.f;
}
Sorry its really messy, and most of it is commented anyway, if you want a clearer version just with the constructors i can do that. Thanks