I know about the mistake on the spelling, i have compensated for that.
BullletController.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Runtime/Engine/Classes/Components/ShapeComponent.h"
#include "BullletController.generated.h"
UCLASS()
class MYGAME_API ABullletController : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ABullletController();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
UShapeComponent* collisionBox;
UPROPERTY(EditAnywhere)
float speed = 400.0f;
UFUNCTION()
void OnOverlap(UPrimitiveComponent* OverLappedComponent,
AActor* OtherActor, UPrimitiveComponent* OtherComponent,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
BullletController.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "HeroController.h"
#include "MyGame.h"
#include "MyGameGameModeBase.h"
#include "BullletController.h"
#include "EnemyController.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "Components/BoxComponent.h"
// Sets default values
ABullletController::ABullletController()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
collisionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Root"));
collisionBox->bGenerateOverlapEvents = true;
collisionBox->OnComponentBeginOverlap.AddDynamic(this, &ABullletController::OnOverlap);
}
// Called when the game starts or when spawned
void ABullletController::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABullletController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector newLocation = GetActorLocation();
newLocation.X -= speed * DeltaTime;
SetActorLocation(newLocation);
if (newLocation.X < -1000.0f) {
this->Destroy();
}
}
void ABullletController::OnOverlap(UPrimitiveComponent* OverLappedComponent,
AActor* OtherActor, UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor->IsA(AEnemyController::StaticClass())) {
this->Destroy();
OtherActor->Destroy();
}
}