// Fill out your copyright notice in the Description page of Project Settings. #include "ProjectileBullet.h" #include "GameFramework/Character.h" #include "GameFramework/ProjectileMovementComponent.h" #include "Kismet/GameplayStatics.h" AProjectileBullet::AProjectileBullet() { ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent")); ProjectileMovementComponent->bRotationFollowsVelocity = true; ProjectileMovementComponent->SetIsReplicated(true); ProjectileMovementComponent->InitialSpeed = InitialSpeed; ProjectileMovementComponent->MaxSpeed = InitialSpeed; } void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { ACharacter* OwnerCharacter = Cast(GetOwner()); if (OwnerCharacter) { AController* OwnerController = OwnerCharacter->Controller; if (OwnerController) { UGameplayStatics::ApplyDamage(OtherActor, Damage, OwnerController, this, UDamageType::StaticClass()); } } Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit); } void AProjectileBullet::BeginPlay() { Super::BeginPlay(); 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); }