일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- Aegis
- DSP
- 유스케이스
- Delegate
- 메카님
- Unreal Engine
- gameplay ability system
- 유니티
- dirty cow
- gas
- gameplay effect
- CTF
- 게임 개발
- Security
- Multiplay
- unity
- gravity direction
- MLFQ
- map design
- animation
- 언리얼 엔진
- ret2libc
- Replication
- photon fusion2
- stride
- MAC
- 게임개발
- Race condition
- ability task
- 언리얼엔진
Archives
- Today
- Total
Replicated
[FPSScoring] 총알 본문
// h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FSBullet.generated.h"
UCLASS()
class FPSSCORING_API AFSBullet : public AActor
{
GENERATED_BODY()
public:
AFSBullet();
protected:
UFUNCTION()
void OnComponentBeginOverlapCallback(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepHitResult);
UPROPERTY()
TObjectPtr<class USphereComponent> Trigger;
UPROPERTY()
TObjectPtr<class UStaticMeshComponent> StaticMeshComp;
UPROPERTY()
TObjectPtr<class UProjectileMovementComponent> Movement;
};
// cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Actor/FSBullet.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Components/SphereComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Physics/FSCollision.h"
#include "Subsystem/FSScoreSubsystem.h"
#include "Game/FSGameMode.h"
// Sets default values
AFSBullet::AFSBullet()
{
Trigger = CreateDefaultSubobject<USphereComponent>(TEXT("Trigger"));
Trigger->InitSphereRadius(5.0f);
Trigger->SetCollisionProfileName(CPROFILE_FSTRIGGER);
RootComponent = Trigger;
Trigger->OnComponentBeginOverlap.AddDynamic(this, &AFSBullet::OnComponentBeginOverlapCallback);
StaticMeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComp"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshRef(TEXT("/Script/Engine.StaticMesh'/Game/Mesh/SM_Bullet.SM_Bullet'"));
if (StaticMeshRef.Succeeded())
{
StaticMeshComp->SetStaticMesh(StaticMeshRef.Object);
}
StaticMeshComp->SetRelativeScale3D(FVector(0.1f, 0.1, 0.1f));
StaticMeshComp->SetupAttachment(RootComponent);
StaticMeshComp->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
Movement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Movement"));
Movement->InitialSpeed = 3000.0f;
Movement->MaxSpeed = 3000.0f;
Movement->bRotationFollowsVelocity = true;
Movement->bShouldBounce = false;
InitialLifeSpan = 3.0f;
}
void AFSBullet::OnComponentBeginOverlapCallback(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepHitResult)
{
UFSScoreSubsystem* ScoreSubsystem = GetWorld()->GetSubsystem<UFSScoreSubsystem>();
if (ScoreSubsystem)
{
ScoreSubsystem->SetScore(ScoreSubsystem->GetScore() + 1);
UE_LOG(LogTemp, Log, TEXT("Hit! - %d"), ScoreSubsystem->GetScore());
AFSGameMode* GameMode = Cast<AFSGameMode>(GetWorld()->GetAuthGameMode());
GameMode->SetScoreText(FString::FromInt(ScoreSubsystem->GetScore()));
}
OtherActor->Destroy();
Destroy();
}
액터에 UProjectileMovementComponent 달아서 사용
void AFSCharacterPlayer::Shoot()
{
if (bIsShooted) return;
bIsShooted = true;
FVector SpawnLocation = GetActorLocation() + GetActorForwardVector() * 100.0f;
FRotator SpawnRotation = GetControlRotation();
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AFSBullet* Bullet = GetWorld()->SpawnActor<AFSBullet>(AFSBullet::StaticClass(), SpawnLocation, SpawnRotation, SpawnParams);
}
플레이어가 쏠 때 회전 ControlRotation으로 정해주면 됨
'언리얼 엔진 > Mini Projects [Unreal]' 카테고리의 다른 글
[FPSScoring] Nanite, 프로파일링 등 그 밖의 최적화 시도 (0) | 2025.02.27 |
---|---|
[FPSScoring] ** Object Pooling in Unreal Engine ** (0) | 2025.02.27 |
[FPSScoring] 게임 저장 기능 (0) | 2025.02.27 |
[FPSScoring] 1인칭 슈팅 스코어링 게임 (0) | 2025.02.27 |