I am sorry for not having code to post that could be helpful with this question… I just have not found anything on this subject if I did I would post something here. I am trying to make an actor collide with another actor, once the actor collides with the actor the actor that touched the actor gets destroyed. I know that there is a sphere collision where the character collides with the actor and the actor gets Destroy(ed)(); The actor needs to touch the other actor not overlap like a trigger box. The static mesh touches the soccerball then the soccerball gets destroyed.
The code below is a static mesh that goes back and forth I created a static mesh that goes back and forth because I want to use this static mesh as a blocker for this incoming ball in the photo here. When the soccer ball collides with this static mesh actor the soccer ball will be destroyed. I am using my character to push the soccerball into the blocker. Also I know I am definitely pushing my luck with this question. I am sorry for the inconvenience.
[https://unrealcpp.com/destroy-actor-on-overlap][1] Yet it is not an overlap it is a collision.
Below is the .cpp file and .h of the “Blocker static mesh.”
#include "EnemyBlocker.h"
// Sets default values
AEnemyBlocker::AEnemyBlocker()
{
// 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;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
}
// Called when the game starts or when spawned
void AEnemyBlocker::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AEnemyBlocker::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector NewLocation = GetActorLocation();
if (NewLocation.X > 500.0f) {
BMove = false;
}
else if (NewLocation.X < -500.0f) {
BMove = true;
}
float factor = (BMove ? 200.f : -200.f);
NewLocation.X += factor * DeltaTime;
SetActorLocation(NewLocation);
}
Below is the .h file and above is the .cpp.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "EnemyBlocker.generated.h"
UCLASS()
class SOCCERLUCAS_API AEnemyBlocker : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AEnemyBlocker();
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)
class UStaticMeshComponent* Mesh;
UPROPERTY(EditAnywhere)
float MaxMove;
/*UPROPERTY(EditAnywhere)
float MaxMoveX;
UPROPERTY(EditAnywhere)
float MaxMoveZ;
UPROPERTY(EditAnywhere)
float Speed = 1;*/
int8 dir = 1;
bool BMove = true;
FVector StartLocation;
FVector SecondStartLocation;
};
Below is the .h file for the soccerball.
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "SoccerBallOne.generated.h"
UCLASS()
class SOCCERLUCAS_API ASoccerBallOne : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ASoccerBallOne();
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)
class UStaticMeshComponent* Mesh;
UPROPERTY(EditAnywhere)
FString Tag;
};
Below is the .cpp file for the soccerball.
// Fill out your copyright notice in the Description page of Project Settings.
#include "SoccerBallOne.h"
#include "Components/StaticMeshComponent.h"
// Sets default values
ASoccerBallOne::ASoccerBallOne()
{
// 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;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("root"));
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
Mesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
Mesh->SetSimulatePhysics(true);
}
// Called when the game starts or when spawned
void ASoccerBallOne::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ASoccerBallOne::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}