194 - Predict Projectile Path

This commit is contained in:
Kingsmedia 2022-05-27 22:37:59 +02:00
parent 8feb5dcbad
commit fec03cfb8e
5 changed files with 32 additions and 1 deletions

Binary file not shown.

View File

@ -16,6 +16,14 @@ public:
AProjectile(); AProjectile();
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
// Used with server-side rewind
bool bUseServerSideRewind = false;
FVector_NetQuantize TraceStart;
FVector_NetQuantize100 InitialVelocity;
UPROPERTY(EditAnywhere)
float InitialSpeed = 15000;
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
void StartDestroyTimer(); void StartDestroyTimer();

View File

@ -12,6 +12,8 @@ AProjectileBullet::AProjectileBullet()
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent")); ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->bRotationFollowsVelocity = true; ProjectileMovementComponent->bRotationFollowsVelocity = true;
ProjectileMovementComponent->SetIsReplicated(true); ProjectileMovementComponent->SetIsReplicated(true);
ProjectileMovementComponent->InitialSpeed = InitialSpeed;
ProjectileMovementComponent->MaxSpeed = InitialSpeed;
} }
void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
@ -28,3 +30,24 @@ void AProjectileBullet::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor,
Super::OnHit(HitComp, OtherActor, OtherComp, NormalImpulse, Hit); 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);
}

View File

@ -21,5 +21,5 @@ public:
protected: protected:
virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) override; virtual void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) override;
virtual void BeginPlay() override;
}; };