Hello,
I am having some problems with my Tank_BP :
- Whenever I stop moving the mouse to control camera rotation and a line trace goes out, the barrel and the turret start shaking vigorously. I do not think this is a problem with the collision because I have tried removing collisions from the meshes. The error began when I created a new level and added a new Tank there. Ever since then, I have been having this issue. Also, since I am in a new level, I have forgotten where to setup the tank player controller as this was done in a couple of lectures back.
I do not think we are supposed to set it up in the project settings in the maps and modes tab but that is where I have set it up currently as such :
This shows the tank hud in all the levels and obviously we do not want that. Where do I set up this tank player controller BP? Is it in the level blueprint? and if so, how do I do it?
- Another issue I am having is that the AI Tank is not aiming or moving, and I have almost the same code as the instructor. Here is my tank AI Controller class but like I said, I do not think that the problem is there.
#include "TankAimingComponent.h"
#include "TankAIController.h"
void ATankAIController::BeginPlay()
{
Super::BeginPlay();
AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>();
// To Do : Look for the nearest tank rather than the player tank everytime
}
void ATankAIController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
TargetTank = GetWorld()->GetFirstPlayerController()->GetPawn();
if (!ensure(TargetTank && AimingComponent)) {return;}
MoveToActor(TargetTank, AcceptanceRadius);
Aim();
AimingComponent->Fire(); // To do : Only fire if the AI Tank is aiming at the player tank
}
void ATankAIController::Aim()
{
// To do : AI Tank looks for nearby tank NOT player tank
auto PlayerLocation = TargetTank->GetActorLocation();
auto Distance = FVector::Distance(PlayerLocation, GetPawn()->GetActorLocation());
if (Distance < AimingComponent->TankRange)
{
AimingComponent->Aim(PlayerLocation);
}
}
I have refactored the aiming and made it into a function. I have also made it so that it takes into the account the reach of the tank. The instructor does do this for the player tank but not the AI Tank. It only took two lines of code so I did that to make it fair. As you can see, I also have a “TO DO” for where I want the AI Tanks to be able to interact with each other as well rather than just targeting the player tank. I think want an AI Tank to aim at whichever tank is nearest. I was thinking that I could get all instances of ATank in the level, find which one has the minimum distance and choose that one to targeted. Does anyone know how to do that?
Another To Do is to let the ai tank to only fire after they have aimed at the target tank or they fire for no reason. Does anyone have tips for that?
Anyway, I cannot seem to figure why the AI Tank is not aiming or not even moving at the least. If you want to see the tank movement component code, you comment below but i do not think that is the problem.
- The last problem I am having is that whenever I recompile my code, firing category in the aiming component of the tank BP resets to default. Meaning that all the settings that I change in the blueprint are reset to the code in C++. This is a big problem, because the aiming component needs a reference to a projectile blueprint and with this issue, I have to select the projectile blueprint in the tank blueprint every time after I compile code. I also change the fire speed (launch speed) to a different value.
Here is what I am talking about:
Here is my code in the header file of the aiming component :
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "TankAimingComponent.generated.h"
class UTankBarrel;
class UTankTurret;
class ATankProjectile;
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BATTLETANK_API UTankAimingComponent : public UActorComponent
{
GENERATED_BODY()
public:
UTankAimingComponent();
protected:
UFUNCTION(BlueprintCallable, Category = "Setup")
void Initialize(UTankBarrel* SetBarrel, UTankTurret* SetTurret);
public:
void Aim(FVector AimLocation);
void MoveBarrelAndTurret(FVector AimDirection);
bool GetAimDirection(FVector &OutAimDirection, FVector AimLocation);
UFUNCTION(BlueprintCallable, Category = "Firing")
void Fire();
UPROPERTY(EditAnywhere, Category = "Firing")
float TankRange = 1000000;
private:
UTankBarrel* Barrel = nullptr;
UTankTurret* Turret = nullptr;
UPROPERTY(EditDefaultsOnly, Category = "Firing")
TSubclassOf<ATankProjectile> TankProjectile = nullptr;
UPROPERTY(EditAnywhere, Category = "Firing")
float FireSpeed = 50000;
UPROPERTY(EditAnywhere, Category = "Firing")
float ReloadTime = 3;
float GameStart = 5;
double LastFireTime = GameStart - ReloadTime;
};
I do not know what is the issue here either and I think this type of issue is happening for the second time now but I do not think I even dealt with it the first time and it just kind of went away.
I would also like to share that I have just brought the Unreal Multiplayer Master course over at udemy and I hope to create Battle Tank a multiplayer game that with real players and spawn AI Tanks when needed. I have also gotten a cool course called “Blender Game Vehicle Creation”, which looks to be promising. I hope to learn 3d modelling as I think it is really important when it comes to expressing your creativity and visions for the game. Hopefully, I can create some tanks of my own and other vehicle assets as well. This course has really been a eye opener. I started game dev about a year ago for a capstone project for grade 12. Back then, I did not know the best resources and did not have much time to devote. Lol I actually started with xcode, and then moved to unity. Unreal has definitely become my favorite engine and I am so excited for unreal engine 5. I am really passionate for game dev and a lot of that comes from this course so thank you guys.