So i’m new to unreal and a noob at programming but basically what happens is ill have everything i like working with live coding ill save and close unreal come back after a few hours to show off a feature in this case i was making a character from the pawn class from scratch and when i open unreal to show it off its completly broken now including now its spawning me at 0,0,0 for some reason, ive also force compiling on startup and recompiled in unreal with livecoding its just a hallow version of what i made ealier here is my code
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
include “CoreMinimal.h”
include “GameFramework/Pawn.h”
include “GameFramework/SpringArmComponent.h”
include “Components/SkeletalMeshComponent.h”
include “Components/CapsuleComponent.h”
include “Camera/CameraComponent.h”
include “NewPlayerPawn.generated.h”
UCLASS()
class CRUNCHTIMEREBIRTH_API ANewPlayerPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn’s properties
ANewPlayerPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
protected:
//Declaring SkeltalMesh which will be our root component
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = “Root Comp”)
USkeletalMeshComponent* SkeletalMeshComp;
//Declaring Camera arm and Camera
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
USpringArmComponent* SpringArmComp;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
UCameraComponent* CameraComp;
//Declaring Default Rotation And Zoom
UPROPERTY(BlueprintReadOnly, Category = "Camera Movement Zoom")
float DefaultCameraZoom;
UPROPERTY(BlueprintReadOnly, Category = "Camera Movement Zoom")
FRotator DefaultCameraRotation;
//declaring Capsule Component
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
UCapsuleComponent* CapsuleComp;
//MOVEMENT LOGIC DECLARATION
FVector MovementDirection;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Movement")
float MovementSpeed = 300.0;
void MoveForwardPlayer(float Value);
void MoveRightPlayer(float Value);
public:
//Getter Functions
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Getter")
FORCEINLINE UCameraComponent* GetCamera() const { return CameraComp; }
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Getter")
FORCEINLINE USpringArmComponent* GetSpringArmComponent() const { return SpringArmComp; }
//getter functions specific for camera arm values
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Getters")
float GetCurrentArmLength();
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Getters")
FRotator GetCurrentRotation();
//Setter Functions
UFUNCTION(BlueprintCallable, Category = "Setters")
virtual void SetArmLength(float ChangeAmount);
UFUNCTION(BlueprintCallable, Category = "Setters")
virtual void SetArmRotation(FRotator ChangeAmount);
UFUNCTION(BlueprintCallable, Category = "Setters")
virtual void SetDefaultArmLength(float ChangeAmount);
//MOVEMENT LOGIC
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
//Mouse Logic for cameraarm
FVector2D MovementInput;
FVector2D CameraInput;
float ZoomFactor;
bool bZoomingIn;
bool bZoomingOut;
float ZoomSpeed;
float DebugMessageTimer;
float DebugMessageInterval;
//Camera Functions
void PitchCamera(float AxisValue);
void YawCamera(float AxisValue);
void ZoomIn();
void ZoomOut();
void ZoomInReleased();
void ZoomOutReleased();
};
AND HERES THE CPP TO THAT HEADER
// Fill out your copyright notice in the Description page of Project Settings.
include “NewPlayerPawn.h”
// Sets default values
ANewPlayerPawn::ANewPlayerPawn()
{
//default values
bZoomingIn = false;
bZoomingOut = false;
ZoomFactor = 0.0;
ZoomSpeed = .5;
DebugMessageTimer = 0.0f;
DebugMessageInterval = .5f;
//default settings for inheriting controllers rotation need to look this up later
bUseControllerRotationPitch = false;
bUseControllerRotationRoll = false;
bUseControllerRotationYaw = false;
//Setting Default Values in the constructor
DefaultCameraZoom = 300.0;
DefaultCameraRotation = FRotator(-20, 90, 0.0);//pitch yaw roll
//Creating declared Objects
SkeletalMeshComp = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("SkeltalMesh"));
SetRootComponent(SkeletalMeshComp);
CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComp"));
CapsuleComp->SetupAttachment(RootComponent);
SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComp"));
/*SpringArmComp->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);*/
CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComp"));
CameraComp->SetupAttachment(SpringArmComp, USpringArmComponent::SocketName);
//CameraSettings
SpringArmComp->SetUsingAbsoluteRotation(false);//whenever pawn rotates Springarm does not follow
SpringArmComp->TargetArmLength = DefaultCameraZoom;//sets inital arm length
SpringArmComp->SetRelativeRotation(DefaultCameraRotation);//sets inital rotation
SpringArmComp->bDoCollisionTest = true; //no clipping camera
SpringArmComp->bEnableCameraLag = true; //no jerking on the camera itself arm still kering
SpringArmComp->bEnableCameraRotationLag = false; //could be jerky may turn on
SpringArmComp->bInheritPitch = false;//MAY NEED TO TURN TO TRUE IF PITCH IS NOT UPDATED TILL MOVING
SpringArmComp->bInheritYaw = false;
SpringArmComp->bInheritRoll = false;
SpringArmComp->SetRelativeLocation(FVector(0.0, 7.9, 196.0));
//define capsule boundries+locaiton
CapsuleComp->InitCapsuleSize(38.0, 94.0);
CapsuleComp->SetRelativeLocation(FVector(0, 0, 90));
// 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;
PrimaryActorTick.bStartWithTickEnabled = true;//not sure why this is here for now probably some rts thing unrealted to cam
}
// Called when the game starts or when spawned
void ANewPlayerPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ANewPlayerPawn::Tick(float DeltaTime)
{
//debug message slow down timer
DebugMessageTimer += DeltaTime;
Super::Tick(DeltaTime);
//CameraMouse
if (bZoomingIn == true)
{
ZoomFactor += DeltaTime / ZoomSpeed;
}
if (bZoomingOut == true)
{
ZoomFactor -= DeltaTime / ZoomSpeed;
}
//clamping zoom factor to a valid range
ZoomFactor = FMath::Clamp<float>(ZoomFactor, -1.0, 1.0);
//newarm length
float NewArmLength = SpringArmComp->TargetArmLength + ZoomFactor;
//ZoomArmLength also clamps it between 0.0 and 300
float ModifiedArmLength = FMath::Clamp(FMath::Lerp(SpringArmComp->TargetArmLength, NewArmLength * 1.5, ZoomFactor), 0.0, 300.0);
//insert values based on zoom factor
CameraComp->FieldOfView = FMath::Lerp<float>(90.0, 90.0, ZoomFactor);
SpringArmComp->TargetArmLength = ModifiedArmLength;
ZoomFactor = 0;
//Rotate SpringArm Sepreate of actor
{
FRotator NewRotation = SpringArmComp->GetRelativeRotation();
NewRotation.Yaw += CameraInput.X;//Camerainput is the mouse
SpringArmComp->SetRelativeRotation(NewRotation);
}
//Rotate ourSpringarmPitch
{
FRotator NewRotation = SpringArmComp->GetComponentRotation();
NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch + CameraInput.Y, -80.0f, -15.0f);
SpringArmComp->SetWorldRotation(NewRotation);
//rotate our actor towards inline of springarm rotation
FRotator ActorRotation = FRotator(0.0, NewRotation.Yaw - 90, 0.0);
FRotator CurrentActorRotation = FMath::RInterpTo(SkeletalMeshComp->GetRelativeRotation(), ActorRotation, DeltaTime, 2);
SkeletalMeshComp->SetRelativeRotation(CurrentActorRotation);
CapsuleComp->SetRelativeRotation(CurrentActorRotation);
}
//rotate our camera back to 90
if (CameraInput.X == 0)
{
FRotator NewRotation = SpringArmComp->GetRelativeRotation();
NewRotation.Yaw = 90;
FRotator BaseRotation = FMath::RInterpTo(SpringArmComp->GetRelativeRotation(), NewRotation, DeltaTime, 2);
SpringArmComp->SetRelativeRotation(BaseRotation);
}
if (DebugMessageTimer >= DebugMessageInterval)
{
if (GEngine)
{
FString DebugMessage = FString::Printf(TEXT("CameraInput.X: %f, CameraInput.Y: %f"), CameraInput.X, CameraInput.Y);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, DebugMessage);
FString ActorRotationDebug = FString::Printf(TEXT("SkeltalMesh: %s"), *SkeletalMeshComp->GetRelativeRotation().ToString());
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, ActorRotationDebug);
FString SpringArmRotationDebug = FString::Printf(TEXT("CurrentSpringArmRotation: %s"), *SpringArmComp->GetRelativeRotation().ToString());
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, SpringArmRotationDebug);
}
DebugMessageTimer = 0;
}
//.IsZero is the FVector way of checking values since it has 3
if (!MovementDirection.IsZero())
{
const FVector NewLocation = GetActorLocation() + (MovementDirection * DeltaTime * MovementSpeed);//movement speed can be any float multiplyer
SetActorLocation(NewLocation);
}
}
//getter functions
float ANewPlayerPawn::GetCurrentArmLength()
{
return SpringArmComp->TargetArmLength;
}
FRotator ANewPlayerPawn::GetCurrentRotation()
{
return SpringArmComp->GetRelativeRotation();
}
//setter functions
void ANewPlayerPawn::SetArmLength(float ChangeAmount)
{
SpringArmComp->TargetArmLength = +ChangeAmount;
}
void ANewPlayerPawn::SetArmRotation(FRotator ChangeAmount)
{
SpringArmComp->SetRelativeRotation(SpringArmComp->GetRelativeRotation() += ChangeAmount);
}
void ANewPlayerPawn::SetDefaultArmLength(float ChangeAmount)
{
SpringArmComp->TargetArmLength = DefaultCameraZoom;
}
void ANewPlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
InputComponent->BindAxis(TEXT(“MoveForward”), this, &ANewPlayerPawn::MoveForwardPlayer);
InputComponent->BindAxis(TEXT(“MoveRight”), this, &ANewPlayerPawn::MoveRightPlayer);
//ZoomIn
InputComponent->BindAction(“ZoomIn”, IE_Pressed, this, &ANewPlayerPawn::ZoomIn);
InputComponent->BindAction(“ZoomIn”, IE_Released, this, &ANewPlayerPawn::ZoomInReleased);
InputComponent->BindAction(“ZoomOut”, IE_Pressed, this, &ANewPlayerPawn::ZoomOut);
InputComponent->BindAction(“ZoomOut”, IE_Released, this, &ANewPlayerPawn::ZoomOutReleased);
//FourAxis CameraMovement
InputComponent->BindAxis(“CameraPitch”, this, &ANewPlayerPawn::PitchCamera);
InputComponent->BindAxis(“CameraYaw”, this, &ANewPlayerPawn::YawCamera);
}
void ANewPlayerPawn::MoveForwardPlayer(float Value)
{//.X for the FVector is the forward and back axis
MovementDirection.Y = FMath::Clamp(Value, -1, 1);
}
void ANewPlayerPawn::MoveRightPlayer(float Value)
{// .Y for FVector is the left and right axis
MovementDirection.X = FMath::Clamp(Value, -1, 1);
}
//CAMERA INPUT FUNCTIONS
void ANewPlayerPawn::PitchCamera(float AxisValue)
{
CameraInput.Y = AxisValue;
}
void ANewPlayerPawn::YawCamera(float AxisValue)
{
CameraInput.X = AxisValue;
}
void ANewPlayerPawn::ZoomIn()
{
bZoomingIn = true;
}
void ANewPlayerPawn::ZoomOut()
{
bZoomingOut = true;
}
void ANewPlayerPawn::ZoomInReleased()
{
bZoomingIn = false;
}
void ANewPlayerPawn::ZoomOutReleased()
{
bZoomingOut = false;
}