diff --git a/Source/Blaster/Components/LagCompensationComponent.cpp b/Source/Blaster/Components/LagCompensationComponent.cpp index bc90b6a..33c7708 100644 --- a/Source/Blaster/Components/LagCompensationComponent.cpp +++ b/Source/Blaster/Components/LagCompensationComponent.cpp @@ -34,6 +34,31 @@ void ULagCompensationComponent::SaveFramePackage(FFramePackage& Package) } } +FFramePackage ULagCompensationComponent::InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime) +{ + const float Distance = YoungerFrame.Time - OlderFrame.Time; + const float InterpFraction = FMath::Clamp((HitTime - OlderFrame.Time) / Distance, 0.f, 1.f); + + FFramePackage InterpFramePackage; + InterpFramePackage.Time = HitTime; + + for (auto& YoungerPair : YoungerFrame.HitBoxInfo) + { + const FName& BoxInfoName = YoungerPair.Key; + const FBoxInformation& OlderBox = OlderFrame.HitBoxInfo[BoxInfoName]; + const FBoxInformation& YoungerBox = YoungerFrame.HitBoxInfo[BoxInfoName]; + + FBoxInformation InterpBoxInfo; + InterpBoxInfo.Location = FMath::VInterpTo(OlderBox.Location, YoungerBox.Location, 1.f, InterpFraction); + InterpBoxInfo.Rotation = FMath::RInterpTo(OlderBox.Rotation, YoungerBox.Rotation, 1.f, InterpFraction); + InterpBoxInfo.BoxExtend = OlderBox.BoxExtend; + + InterpFramePackage.HitBoxInfo.Add(BoxInfoName, InterpBoxInfo); + } + + return InterpFramePackage; +} + void ULagCompensationComponent::ShowFramePackage(const FFramePackage& Package, const FColor Color) { for (auto& BoxInfo : Package.HitBoxInfo) diff --git a/Source/Blaster/Components/LagCompensationComponent.h b/Source/Blaster/Components/LagCompensationComponent.h index ee821b3..3cc5408 100644 --- a/Source/Blaster/Components/LagCompensationComponent.h +++ b/Source/Blaster/Components/LagCompensationComponent.h @@ -48,6 +48,7 @@ public: protected: virtual void BeginPlay() override; void SaveFramePackage(FFramePackage& Package); + FFramePackage InterpBetweenFrames(const FFramePackage& OlderFrame, const FFramePackage& YoungerFrame, float HitTime); private: