blaster/Source/Blaster/Weapon/ProjectileBullet.cpp

73 lines
2.3 KiB
C++
Raw Normal View History

2022-05-07 11:03:19 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "ProjectileBullet.h"
#include "GameFramework/Character.h"
2022-05-19 09:10:41 +00:00
#include "GameFramework/ProjectileMovementComponent.h"
2022-05-07 11:03:19 +00:00
#include "Kismet/GameplayStatics.h"
2022-05-19 09:10:41 +00:00
AProjectileBullet::AProjectileBullet()
{
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->bRotationFollowsVelocity = true;
ProjectileMovementComponent->SetIsReplicated(true);
2022-05-27 20:37:59 +00:00
ProjectileMovementComponent->InitialSpeed = InitialSpeed;
ProjectileMovementComponent->MaxSpeed = InitialSpeed;
2022-05-19 09:10:41 +00:00
}
2022-05-27 20:52:03 +00:00
#if WITH_EDITOR
void AProjectileBullet::PostEditChangeProperty(FPropertyChangedEvent& Event)
{
Super::PostEditChangeProperty(Event);
const FName PropertyName = Event.Property != nullptr ? Event.Property->GetFName() : NAME_None;
if (PropertyName == GET_MEMBER_NAME_CHECKED(AProjectileBullet, InitialSpeed))
{
if (ProjectileMovementComponent)
{
ProjectileMovementComponent->InitialSpeed = InitialSpeed;
ProjectileMovementComponent->MaxSpeed = InitialSpeed;
}
}
}
#endif
2022-05-07 11:03:19 +00:00
void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
ACharacter* OwnerCharacter = Cast<ACharacter>(GetOwner());
if (OwnerCharacter)
{
AController* OwnerController = OwnerCharacter->Controller;
if (OwnerController)
{
UGameplayStatics::ApplyDamage(OtherActor, Damage, OwnerController, this, UDamageType::StaticClass());
}
}
Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit);
}
2022-05-27 20:37:59 +00:00
void AProjectileBullet::BeginPlay()
{
Super::BeginPlay();
2022-05-27 22:28:02 +00:00
/*
2022-05-27 20:37:59 +00:00
FPredictProjectilePathParams PathParams;
PathParams.bTraceWithChannel = true;
PathParams.bTraceWithCollision = true;
PathParams.DrawDebugTime = 5.f;
PathParams.DrawDebugType = EDrawDebugTrace::ForDuration;
PathParams.LaunchVelocity = GetActorForwardVector() * InitialSpeed;
PathParams.MaxSimTime = 4.f;
PathParams.ProjectileRadius = 5.f;
PathParams.SimFrequency = 30.f;
PathParams.StartLocation = GetActorLocation();
PathParams.TraceChannel = ECollisionChannel::ECC_Visibility;
PathParams.ActorsToIgnore.Add(this);
FPredictProjectilePathResult PathResult;
UGameplayStatics::PredictProjectilePath(this, PathParams, PathResult);
2022-05-27 22:28:02 +00:00
*/
2022-05-27 20:37:59 +00:00
}