응애맘마조
231228 강의 본문
날아오는 표적을 맞추는 클레이 사격을 어제 만드는 실습을 하고 오늘 풀이를 했습니다. 날아오는 클레이와 충돌처리를 담당하는 클래스를 따로 만들었습니다.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "C_Clay.generated.h"
UCLASS()
class SCENEA_API AC_Clay : public AActor
{
GENERATED_BODY()
private:
UPROPERTY(VisibleDefaultsOnly)
class UStaticMeshComponent* Mesh;
int32 score;
public:
// Sets default values for this actor's properties
AC_Clay();
void Fire(FVector Pos, FVector Dir, int32 Score);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};
#include "C_Clay.h"
#include "Components/StaticMeshComponent.h"
#include "Global.h"
// Sets default values
AC_Clay::AC_Clay()
{
Mesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
RootComponent = Mesh;
UStaticMesh* mesh;
CHelpers::GetAsset<UStaticMesh>(&mesh, "StaticMesh'/Game/Scene2/Mesh/Cylinder.Cylinder'");
Mesh->SetStaticMesh(mesh);
Mesh->SetSimulatePhysics(true);
Mesh->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
}
void AC_Clay::Fire(FVector Pos, FVector Dir, int32 Score)
{
SetActorLocation(Pos);
Mesh->AddImpulse(Dir * 100.0f);
score = Score;
}
// Called when the game starts or when spawned
void AC_Clay::BeginPlay()
{
Super::BeginPlay();
}
클레이의 클래스입니다.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "C_ClaySpawner.generated.h"
UCLASS()
class SCENEA_API AC_ClaySpawner : public AActor
{
GENERATED_BODY()
private:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<class AC_Clay> SpawnClass;
public:
// Sets default values for this actor's properties
AC_ClaySpawner();
UPROPERTY(EditInstanceOnly)
FVector Point1;
UPROPERTY(EditInstanceOnly)
FVector Point2;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION()
void Spawn();
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "C_ClaySpawner.h"
#include "Global.h"
#include "C_Clay.h"
// Sets default values
AC_ClaySpawner::AC_ClaySpawner()
{
// 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;
CHelpers::GetClass<AC_Clay>(&SpawnClass,
"Blueprint'/Game/MiniGame/BP_C_Clay.BP_C_Clay_C'");
}
// Called when the game starts or when spawned
void AC_ClaySpawner::BeginPlay()
{
Super::BeginPlay();
UKismetSystemLibrary::K2_SetTimer(this, "Spawn", 1.0f, true);
}
// Called every frame
void AC_ClaySpawner::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AC_ClaySpawner::Spawn()
{
AC_Clay* spawn = GetWorld()->SpawnActor<AC_Clay>(SpawnClass);
spawn->Fire(Point1, FVector(0, -1500, 700), 1);
AC_Clay* spawn2 = GetWorld()->SpawnActor<AC_Clay>(SpawnClass);
spawn2->Fire(Point2, FVector(-1700, -1500, 0), 1);
}
새로 생성되는 클레이 스폰입니다. 충돌처리는 이전에 사용한 충돌처리를 그대로 사용했습니다.
맞추지는 못했지만 잘 실행됩니다.
읽어주셔서 감사합니다.
Comments