64 lines
2.8 KiB
Lua
64 lines
2.8 KiB
Lua
---@class BP_TrackKillerCamera_C:AActor
|
|
---@field Camera UCameraComponent
|
|
---@field DefaultSceneRoot USceneComponent
|
|
---@field EnableTime float
|
|
---@field InterpSpeed float
|
|
--Edit Below--
|
|
---@type BP_TrackKillerCamera_C
|
|
local BP_TrackKillerCamera = {
|
|
bEnableMove = false;
|
|
KillerPawn = nil;
|
|
DelayDisableHandle = nil;
|
|
};
|
|
|
|
|
|
function BP_TrackKillerCamera:ReceiveBeginPlay()
|
|
self.SuperClass.ReceiveBeginPlay(self);
|
|
if not UGCGameSystem.IsServer() then
|
|
UGCEventSystem.AddListener(EventEnum.PlayerDeathInfo, self.PlayerDeath, self)
|
|
UGCLogSystem.Log("[BP_TrackKillerCamera_ReceiveBeginPlay] ")
|
|
end
|
|
end
|
|
|
|
function BP_TrackKillerCamera:PlayerDeath(VictimKey, CauserKey)
|
|
if GlobalConfigs.GameSetting.EnableLerpCamera then
|
|
UGCLogSystem.Log("[BP_TrackKillerCamera_PlayerDeath]")
|
|
if UGCSystemLibrary.GetLocalPlayerKey() == VictimKey then
|
|
UGCLogSystem.Log("[BP_TrackKillerCamera_PlayerDeath] VictimKey:%d, CauserKey:%d ", VictimKey, CauserKey)
|
|
self.KillerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(CauserKey)
|
|
if UE.IsValid(self.KillerPawn) then
|
|
local TargetPos_ = self.KillerPawn:K2_GetActorLocation()
|
|
local TargetRot_ = self.KillerPawn:K2_GetActorRotation()
|
|
self:K2_SetActorLocation(TargetPos_)
|
|
self:K2_SetActorRotation(TargetRot_)
|
|
self.bEnableMove = true
|
|
if self.DelayDisableHandle ~= nil then UGCEventSystem.StopTimer(self.DelayDisableHandle) self.DelayDisableHandle = nil end
|
|
self.DelayDisableHandle = UGCEventSystem.SetTimer(self, function() self.bEnableMove = false end, self.EnableTime)
|
|
else
|
|
UGCLogSystem.LogError("[BP_TrackKillerCamera_PlayerDeath] KillerPawn is nil. CauserKey:%s", tostring(CauserKey))
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
function BP_TrackKillerCamera:GetTargetPosAndRot()
|
|
return self.KillerPawn:K2_GetActorLocation(), self.KillerPawn:K2_GetActorRotation()
|
|
-- return self.KillerPawn.ScopingCamera:K2_GetComponentLocation(), self.KillerPawn.ScopingCamera:K2_GetComponentRotation()
|
|
end
|
|
|
|
function BP_TrackKillerCamera:ReceiveTick(DeltaTime)
|
|
self.SuperClass.ReceiveTick(self, DeltaTime);
|
|
if self.bEnableMove then
|
|
if UE.IsValid(self.KillerPawn) then
|
|
local TargetPos_, TargetRot_ = self:GetTargetPosAndRot()
|
|
self:K2_SetActorLocation(KismetMathLibrary.VInterpTo(self:K2_GetActorLocation(), TargetPos_, DeltaTime, self.InterpSpeed))
|
|
self:K2_SetActorRotation(KismetMathLibrary.RInterpTo(self:K2_GetActorRotation(), TargetRot_, DeltaTime, self.InterpSpeed))
|
|
else
|
|
UGCLogSystem.Log("[BP_TrackKillerCamera_ReceiveTick] KillerPawn is nil")
|
|
self.bEnableMove = false
|
|
end
|
|
end
|
|
end
|
|
|
|
return BP_TrackKillerCamera; |