Cant move Tank anymore

Hi I am having an issue when I press play. After finishing this lecture i tried to move my tank but i cant anymore. I added the Cast and Pawntank.h and still cant move. Can someone please help?

We can’t see which lecture here afaik sadly, can you show us where you’re calling the move?

I had the move function originally in the tick function. But i had to remove it on the APawnTurret.cpp because i couldnt call the function in that file. I got a compilation error when i left it there. The lecture im at is 142 Find Distance between.

Was your turret supposed to inherit from the tank class by any chance? If you removed it then that’d be why you can’t move tbh.

the turret class is a child class from PawnBase not the PawnTurret. I included the PawnTank class in the header file for PawnTurret. I followed everything the lecture told me to do. I dont understand why it doesnt work.

The compilation error before may have been a very good clue at some minor deviation between you and the instructor. If you throw it back what error does it give?

So that says it doesn’t recognize the source for those things basically. Can you show the code where you call it? I’m pretty sure cpp 22 on there will show it all, I am guessing it’s not pulling through from the other file right now. Might need a little above/below there to be sure.

I apologize for the slow response. I saw where the instructor deleted the same code on paste. Sadly end of my workday so I’ll look more when I get home and see if the heart of it becomes clearer when on my pc instead of my phone.

Hi
You added functions to PawnTurret.cpp, but you should have added it to PawnTank.cpp. Try it and let us know about the results.

where in the PawnTank.cpp would i put them? Before creating Pawn Turret the tick function was in PawnTank then the instructor removed it in the APawnTurret lecture. At that lecture he removed the move and rotate functions and moved the tick and begin play to PawnTurret.h. I followed his instructions completely and he could move his tank at the end of the lecture but i couldnt. BTW when i added the tick function back to PawnTank and added Move and Rotate functions into tick function the tank started to move again. But im concerned if this will give me problems down the road because this is not the way the instructor did it.

Would you mind posting your entire code (please use a code block by using the </> button). It’s a bit hard to follow it with random snippets of it.

1 Like
#include "PawnTurret.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::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
}

void APawnTurret::CheckFireCondition()
{
    // If player is null or dead then bail
    if(!PlayerPawn)
    {
        return;
    }
    // if player is in range then fire
    if(ReturnDistanceToPlayer() <= FireRange)
    {
        //Fire
        UE_LOG(LogTemp, Warning, TEXT("Fire Condition Success"));
    }
    
}

float APawnTurret::ReturnDistanceToPlayer()
{
    if(!PlayerPawn)
    {
        return 0.0f;
    }
    
    return FVector::Dist(PlayerPawn->GetActorLocation(), GetActorLocation());
    
        
}

That’s not all of it. Could you also provide the header as well as the tank and base classes?

Its okay I fixed the issue.

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

Privacy & Terms