116 lines
3.8 KiB
Lua
116 lines
3.8 KiB
Lua
|
---@class BP_Hook_C:AActor
|
||
|
---@field Cable UCableComponent
|
||
|
---@field Cylinder UStaticMeshComponent
|
||
|
---@field ST_Prop_Hook UStaticMeshComponent
|
||
|
---@field DefaultSceneRoot USceneComponent
|
||
|
--Edit Below--
|
||
|
---@type BP_Hook_C
|
||
|
local BP_Hook = {
|
||
|
MoveState = 0;
|
||
|
bHooking = false;
|
||
|
};
|
||
|
|
||
|
|
||
|
function BP_Hook:ReceiveBeginPlay()
|
||
|
self.SuperClass.ReceiveBeginPlay(self);
|
||
|
---@field K2_AttachToComponent:fun(Parent:USceneComponent,SocketName:FName,LocationRule:EAttachmentRule,RotationRule:EAttachmentRule,ScaleRule:EAttachmentRule,bWeldSimulatedBodies:bool):bool
|
||
|
--self.Cable:K2_AttachToComponent(self.ST_Prop_Hook, "", EAttachmentRule.KeepRelative, EAttachmentRule.SnapToTarget, EAttachmentRule.KeepRelative, true)
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
--[[
|
||
|
function BP_Hook:ReceiveEndPlay()
|
||
|
self.SuperClass.ReceiveEndPlay(self);
|
||
|
end
|
||
|
--]]
|
||
|
|
||
|
--[[
|
||
|
function BP_Hook:GetReplicatedProperties()
|
||
|
return
|
||
|
end
|
||
|
--]]
|
||
|
|
||
|
--[[
|
||
|
function BP_Hook:GetAvailableServerRPCs()
|
||
|
return
|
||
|
end
|
||
|
--]]
|
||
|
|
||
|
function BP_Hook:SetPlayerKey(InPlayerKey, InIsRight)
|
||
|
self.OwnerPlayer = InPlayerKey
|
||
|
self.IsRight = InIsRight
|
||
|
end
|
||
|
|
||
|
function BP_Hook:GetOwnerPlayer()
|
||
|
return self.OwnerPlayer, self.IsRight
|
||
|
end
|
||
|
|
||
|
function BP_Hook:FireHook(InStartPos, EndPos, InFlyTime, Owner, TargetComponentName, GearSocketName)
|
||
|
self.StartPos = InStartPos
|
||
|
self.TargetPos = EndPos
|
||
|
local TargetRotation = KismetMathLibrary.MakeRotFromX(VectorHelper.Sub(self.TargetPos, self.StartPos))
|
||
|
self:K2_SetActorLocation(self.StartPos)
|
||
|
self:K2_SetActorRotation(TargetRotation)
|
||
|
self.FlyTime = InFlyTime
|
||
|
self.MoveStartTime = UGCSystemLibrary.GetGameTime()
|
||
|
self.MoveState = 1
|
||
|
--self:SetActorHiddenInGame(false)
|
||
|
self:SetHooking(true)
|
||
|
|
||
|
self.Cable:SetAttachEndTo(Owner, TargetComponentName, GearSocketName)
|
||
|
|
||
|
UGCLogSystem.Log("[BP_Hook_FireHook] StartPos:%s, TargetPos:%s", VectorHelper.ToString(self.StartPos), VectorHelper.ToString(self.TargetPos))
|
||
|
end
|
||
|
|
||
|
function BP_Hook:RecoverHook()
|
||
|
self.StartPos = self:K2_GetActorLocation()
|
||
|
self.MoveStartTime = UGCSystemLibrary.GetGameTime()
|
||
|
self.MoveState = 2
|
||
|
UGCLogSystem.Log("[BP_Hook_RecoverHook]")
|
||
|
end
|
||
|
|
||
|
|
||
|
function BP_Hook:ReceiveTick(DeltaTime)
|
||
|
self.SuperClass.ReceiveTick(self, DeltaTime);
|
||
|
if self.bHooking then
|
||
|
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.OwnerPlayer)
|
||
|
-- local PlayerSocketPos = TargetPawn:GetHookFireStartPos(self.IsRight)
|
||
|
--local LocalPos = self:K2_GetActorLocation()
|
||
|
--local Dir = VectorHelper.Sub(LocalPos, PlayerSocketPos)
|
||
|
--local CableRotation = KismetMathLibrary.MakeRotFromX(Dir)
|
||
|
--self.Cylinder:K2_SetWorldRotation(CableRotation)
|
||
|
--self.Cylinder:SetWorldScale3D({X = VectorHelper.Length(Dir) / 100., Y = 0.08, Z = 0.08})
|
||
|
|
||
|
|
||
|
|
||
|
if not UE.IsValid(TargetPawn) then
|
||
|
self:SetHooking(false)
|
||
|
self.MoveState = 0
|
||
|
end
|
||
|
if self.MoveState > 0 then
|
||
|
local NowTime = UGCSystemLibrary.GetGameTime()
|
||
|
if self.MoveState == 2 then
|
||
|
self.TargetPos = TargetPawn:GetHookFireStartPos(self.IsRight)
|
||
|
end
|
||
|
local LerpAlpha = (NowTime - self.MoveStartTime) / self.FlyTime
|
||
|
local TargetLocation = KismetMathLibrary.VLerp(self.StartPos, self.TargetPos, math.clamp(LerpAlpha, 0., 1.))
|
||
|
self:K2_SetActorLocation(TargetLocation)
|
||
|
UGCLogSystem.Log("[BP_Hook_ReceiveTick] MoveState:%s, TargetLocation:%s, LerpAlpha:%s", tostring(self.MoveState), VectorHelper.ToString(TargetLocation), tostring(LerpAlpha))
|
||
|
if LerpAlpha >= 1. then
|
||
|
if self.MoveState == 2 then
|
||
|
self:SetHooking(false)
|
||
|
end
|
||
|
self.MoveState = 0
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function BP_Hook:SetHooking(InbHooking)
|
||
|
self.bHooking = InbHooking
|
||
|
self:SetActorHiddenInGame(not self.bHooking)
|
||
|
end
|
||
|
|
||
|
return BP_Hook;
|