Issue with Move Direction not having correct Identifier

Not sure what I did wrong. It feels like the include isn’t actually working properlty or maybe I am missing the correct include.

Anyone have an idea what is wrong??? Both of the objects should have identifiers since they are being declared.
When I compile I keep getting an error about:

D:\Epic Games\UE_4.26\Unreal Training\ToonTanks\Source\ToonTanks\Pawns\PawnTank.cpp(55) : error C2065: ‘MoveDirection’: undeclared identifier
D:\Epic Games\UE_4.26\Unreal Training\ToonTanks\Source\ToonTanks\Pawns\PawnTank.cpp(43) : error C2065: ‘MoveDirection’: undeclared identifier

// Fill out your copyright notice in the Description page of Project Settings.

#include "PawnTank.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "GameFrameWork/Actor.h"

APawnTank::APawnTank()
{
    SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
    SpringArm->SetupAttachment(RootComponent);

    Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    Camera->SetupAttachment(SpringArm);
}

// Called when the game starts or when spawned
void APawnTank::BeginPlay()
{
    Super::BeginPlay();
}

// Called every frame
void APawnTank::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    Rotate();
    Move();
    
    
}

// Called to bind functionality to input
void APawnTank::SetupPlayerInputComponent(UInputComponent *PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);
    PlayerInputComponent->BindAxis("MoveFoward", this, &APawnTank::CalculateMoveInput);
    PlayerInputComponent->BindAxis("Turn", this, &APawnTank::CalculateRotateInput);
}

void APawnTank::CalculateMoveInput(float Value)
{
    MoveDirection = FVector(Value * MoveSpeed * GetWorld()->DeltaTimeSeconds, 0, 0);
}

void APawnTank::CalculateRotateInput(float Value)
{
    float RotateAmount = Value * RotateSpeed * GetWorld()->DeltaTimeSeconds;
    FRotator Rotation = FRotator(0, RotateAmount, 0);
    RotationDirection = FQuat(Rotation);
}

void APawnTank::Move()
{
    AddActorLocalOffset(MoveDirection, true);
}

void APawnTank::Rotate()
{
    AddActorLocalRotation(RotationDirection, true);
}

Maybe this is related?

Could you post your header file?

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "PawnBase.h"
#include "Math/Rotator.h"
#include "Math/Quat.h"
#include "Math/Vector.h"
#include "PawnTank.generated.h"

class USpringArmComponent;
class UCameraComponent;
/**
 * 
 */
UCLASS()
class TOONTANKS_API APawnTank : public APawnBase
{
	GENERATED_BODY()

private:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	USpringArmComponent *SpringArm;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	UCameraComponent *Camera;

	FVector MoveDirection;
	FQuat RotationDirection;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (AllowPrivateAccess = "true"))
	float MoveSpeed = 100.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (AllowPrivateAccess = "true"))
	float RotateSpeed = 100.0f;

	void CalculateMoveInput(float Value);
	void CalculateRotateInput(float Value);

	void Move();
	void Rotate();

	void JulienFucntion();

public:
	APawnTank();

	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent) override;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
};

That is a little strange. It’s definitely declared as far as I can tell. What are lines 55 an 43 in the cpp? Also are you sure both files are saved?

I finally got it!

// Fill out your copyright notice in the Description page of Project Settings.

#include "PawnTurret.h"
#include "Kismet/GameplayStatics.h"
#include "PawnTank.h"

// Called when the game starts or when spawned
void APawnTurret::BeginPlay()
{
    Super::BeginPlay();

    GetWorld()->GetTimerManager().SetTimer(FireRateTimerHandle, this, &APawnTurret::CheckFireCondition, FireRate, true);

    PlayerPawn = Cast<APawnTank>(UGameplayStatics::GetPlayerPawn(this, 0));
}



void APawnTurret::HandleDestruction() 
{
    Super::HandleDestruction();
    Destroy();
}

// Called every frame
void APawnTurret::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    if(!PlayerPawn || ReturnDistanceToPlayer() < FireRange)
    {
     
        RotateTurret(PlayerPawn->GetActorLocation());
    }
}

void APawnTurret::CheckFireCondition()
{
    // if the player is null || is Dea then bail!!

    // if the play is in range then fire.

    if (!PlayerPawn)
    {
        return;
    }
    if(ReturnDistanceToPlayer()<= FireRange)
    {
        Fire();
    }

}

float APawnTurret::ReturnDistanceToPlayer() 
{
     if (!PlayerPawn)
    {
        return 0.0f;
    }

    // two ways of writing the below code 
    //  return FVector::Dist(PlayerPawn->GetActorLocation(),GetActorLocation()); 
    // or the below. I opted for the below because it is a bit easier to read but both do the same thing. 

    float Distance = FVector::Dist(PlayerPawn->GetActorLocation(),GetActorLocation());
    return Distance;


}

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms