local FixedC0s, Bounds = {}, {}
local MotorList : {[Motor6D | typeof(ReplicatedStorage.Aligns)] : CFrame | {CFrame} | number} = {}
RunService.PostSimulation:ConnectParallel(function(DeltaTime)
if PerformanceMode.Value then
return
end
local LerpDT = 1-math.exp(-12*DeltaTime)
local Radius = 150 do
BoundsDelta += DeltaTime
if BoundsDelta >= 3 then
if Bounds then
table.clear(Bounds)
end
Bounds = workspace:GetPartBoundsInRadius(Camera.Focus.Position, Radius, HitboxParams)
if PlayerHurtbox and not table.find(Bounds, PlayerHurtbox) then
Bounds[#Bounds+1] = PlayerHurtbox
end
BoundsDelta = 0
end
end
for _, Hurtbox in next, Bounds do
if not Hurtbox.Parent then
continue
end
local Attachment : Weld = Hurtbox:FindFirstChild("Weld")
if not Attachment then
continue
end
local Parent = Attachment and Attachment.Part1
local Character : Globals.CharacterType = Parent and Parent.Parent
local Root = Character and Character.PrimaryPart
if not (Root and Character:GetAttribute("Loaded")) then
continue
end
local EntityProfile = EntityProfiles[Character]
if not EntityProfile then
continue
end
local StateProfile = StateProfiles[Character]
if not StateProfile then
continue
elseif StateProfile.TimestopFrozen then
continue
end
local Humanoid : typeof(Character.Humanoid), Head : typeof(Character.Head), Torso : typeof(Character.Torso) =
EntityProfile.Humanoid, EntityProfile.Head, EntityProfile.Torso
if not Humanoid or not Head or not Torso then
continue
end
local IsPlayerCharacter = PlayerCharacter == Character
local IsShiftlocked, CameraCFrame do
IsShiftlocked = IsPlayerCharacter and UserInputs.MouseBehavior == LockCenter or Character.CameraLocked.Value
CameraCFrame = IsPlayerCharacter and Camera.CFrame or Character.CameraCFrame.Value
end
local NilNetworkAligns : typeof(ReplicatedStorage.Aligns) = EntityProfile.NilNetworkAligns
if NilNetworkAligns then
MotorList[NilNetworkAligns] = DeltaTime
end
local SideVector, FrontVector = 0, 0
local RootCFrame = Root.CFrame
local RootLV = RootCFrame.LookVector
local CharacterVelocity = Root.AssemblyLinearVelocity
local CharacterVelocityMagnitude = CharacterVelocity.Magnitude
if CharacterVelocityMagnitude > 0.5 then
local Unit = CharacterVelocity.Unit do
SideVector = RootCFrame.RightVector:Dot(Unit)
FrontVector = RootLV:Dot(Unit)
end
end
local Neck : typeof(Torso["Neck"]) = EntityProfile["Neck"]
local RightHip : typeof(Torso["Right Hip"]) = EntityProfile["Right Hip"]
local LeftHip : typeof(Torso["Left Hip"]) = EntityProfile["Left Hip"]
local RightShoulder : typeof(Torso["Right Shoulder"]) = EntityProfile["Right Shoulder"]
local LeftShoulder : typeof(Torso["Left Shoulder"]) = EntityProfile["Left Shoulder"]
local RootJoint : typeof(Root["RootJoint"]) = EntityProfile["RootJoint"] or EntityProfile["Root Hip"]
if not Neck or not RightHip or not LeftHip or not RightShoulder or not LeftShoulder or not RootJoint then
continue
end
local NeckC0 : CFrame, RightHipC0 : CFrame, LeftHipC0 : CFrame,
RightShoulderC0 : CFrame, LeftShoulderC0 : CFrame, RootJointC1 : CFrame, RootJointC0 : CFrame =
EntityProfile["NeckC0"], EntityProfile["Right HipC0"], EntityProfile["Left HipC0"],
EntityProfile["Right ShoulderC0"], EntityProfile["Left ShoulderC0"],
EntityProfile.RootJointC1 or EntityProfile["Root HipC1"],
EntityProfile.RootJointC0 or EntityProfile["Root HipC0"]
if not NeckC0 or not RightHipC0 or not LeftHipC0 or not RightShoulderC0
or not LeftShoulderC0 or not RootJointC1 or not RootJointC0 then
continue
end
local RJointC0 = RootJointC0; if not StateProfile.Grabbed and not StateProfile.Grabbing then
if not Attachment.Enabled then
if not IsPlayerCharacter and not Root.Anchored and not StateProfile.Ragdoll then
local ObjectSpace = RootCFrame:ToObjectSpace(Character.ClientCFrame.Value)
local Position; if IntepolationPrediction > 0 then
local Alpha = DeltaTime*IntepolationPrediction*10 do
if CharacterVelocityMagnitude <= 1 then
Alpha = LerpDT
end
end
local Magnitude = (ObjectSpace.Position-RootJoint.C0.Position).Magnitude*IntepolationPrediction+1
Alpha *= Magnitude; if Alpha > 1 then
Alpha = 1
end
Position = RootJoint.C0.Position:Lerp(ObjectSpace.Position, Alpha) do
local Origin, Offset = RootCFrame.Position, Root.PivotOffset.Position + Vector3.yAxis*0.1
local Raycast = workspace:Raycast(Origin+Vector3.yAxis*Position.Y, Offset, Globals.MapRParams)
if Raycast then
Position += Vector3.yAxis*(((Raycast.Position-Offset)-Origin).Y-Position.Y)
end
end
end
local Angle do
local _, RotationY = ObjectSpace.Rotation:ToOrientation()
Angle = CFrame.Angles(0, 0, RotationY)
end
if Position then
RJointC0 = CFrame.new(Position)*RJointC0.Rotation*Angle
else
RJointC0 *= Angle
end
end
else
local ObjectSpace = RootCFrame:ToObjectSpace(Character.ClientCFrame.Value)
local Angle do
local _, RotationY = ObjectSpace.Rotation:ToOrientation()
Angle = CFrame.Angles(0, 0, RotationY)
end
RJointC0 = CFrame.new(ObjectSpace.Position)*RJointC0.Rotation*Angle
end
end
if Root.Anchored or Humanoid.PlatformStand or Humanoid.Sit or Humanoid:GetState() == Climbing
or StateProfile.Grabbed or StateProfile.Grabbing then
if not FixedC0s[Character] then
MotorList[Neck] = NeckC0
MotorList[RootJoint] = {RJointC0, RootJointC1}
MotorList[RightHip] = RightHipC0
MotorList[LeftHip] = LeftHipC0
MotorList[RightShoulder] = RightShoulderC0
MotorList[LeftShoulder] = LeftShoulderC0
FixedC0s[Character] = true
end
continue
end
if FixedC0s[Character] then
FixedC0s[Character] = nil
end
local Attacking = StateProfile.Attacking; if not (
Attacking and not StateProfile.CanSync or StateProfile.Stunned or StateProfile.M1ing or StateProfile.NoSync
) then
local RootRotate, FrontRadius = math.rad(SideVector)*7, math.rad(FrontVector)*15
if Attacking then
RootRotate /= 2
FrontRadius /= 2
end
local RJointC1
local YAxis = 0
local Dist, Diff, YLevel; if CameraCFrame and not Attachment.Enabled then
local CameraPosition = CameraCFrame.Position do
Dist, Diff, YLevel =
(Head.Position-CameraPosition).Magnitude,
Head.Position.Y-CameraPosition.Y,
(((Head.Position-CameraPosition).Unit):Cross(RootLV)).Y
YAxis = math.asin(Diff/Dist)*0.4
if Attacking then
YAxis /= 1.5
end
if IsPlayerCharacter then
local Offset = Root.Size.Z/2; if YAxis > 0 then
Offset *= -1
end
local Raycast = workspace:Raycast(Root.Position, RootLV*(Offset-YAxis*4), Globals.MapRParams)
if Raycast then
YAxis = Raycast.Distance/-Offset/16
end
end
end
MotorList[Neck] = Neck.C0:Lerp(
NeckC0*CFrame.Angles(-YAxis*1.5-FrontRadius, 0, (not IsShiftlocked and -YLevel or 0)+RootRotate),
LerpDT
)
do -- RootJoint
local Product = RootJointC1*CFrame.Angles(YAxis-FrontRadius, RootRotate, RootRotate)
RJointC1 = RootJoint.C1:Lerp(
Product + Product:VectorToWorldSpace(RootJointC0:VectorToObjectSpace(Vector3.new(0, math.abs(YAxis)/4, -YAxis))),
LerpDT
)
end
MotorList[RightShoulder] = RightShoulder.C0:Lerp(RightShoulderC0*CFrame.Angles(0, 0, YAxis*1.5), LerpDT)
MotorList[LeftShoulder] = LeftShoulder.C0:Lerp(LeftShoulderC0*CFrame.Angles(0, 0, -YAxis*1.5), LerpDT)
else
MotorList[Neck] = Neck.C0:Lerp(NeckC0*CFrame.Angles(-FrontRadius, 0, RootRotate), LerpDT)
RJointC1 = RootJoint.C1:Lerp(RootJointC1*CFrame.Angles(-FrontRadius, RootRotate, RootRotate), LerpDT)
MotorList[RightShoulder] = RightShoulder.C0:Lerp(RightShoulderC0, LerpDT)
MotorList[LeftShoulder] = LeftShoulder.C0:Lerp(LeftShoulderC0, LerpDT)
end
MotorList[RootJoint] = {RJointC0, RJointC1}
MotorList[RightHip] = RightHip.C0:Lerp(
RightHipC0*CFrame.Angles(0, RootRotate/2.5*(-SideVector > 0 and 0.5 or -1), -YAxis),
LerpDT
)
MotorList[LeftHip] = LeftHip.C0:Lerp(
LeftHipC0*CFrame.Angles(0, RootRotate/2.5*(SideVector > 0 and 0.5 or -1), YAxis),
LerpDT
)
else
MotorList[Neck] = Neck.C0:Lerp(NeckC0, LerpDT)
MotorList[RootJoint] = {RJointC0, RootJoint.C1:Lerp(RootJointC1, LerpDT)}
MotorList[RightHip] = RightHip.C0:Lerp(RightHipC0, LerpDT)
MotorList[LeftHip] = LeftHip.C0:Lerp(LeftHipC0, LerpDT)
MotorList[RightShoulder] = RightShoulder.C0:Lerp(RightShoulderC0, LerpDT)
MotorList[LeftShoulder] = LeftShoulder.C0:Lerp(LeftShoulderC0, LerpDT)
end
end
task.synchronize() do
for Motor, Value in next, MotorList do
local MotorName = Motor.Name
if MotorName == "RootJoint" then
for Index, Coordinate in next, Value do
Motor[Index == 1 and "C0" or "C1"] = Coordinate
Value[Index] = nil
end
table.clear(Value)
elseif MotorName == "NilNetworkAligns" then
Motor.SmoothTime = Value
else
Motor.C0 = Value
end
MotorList[Motor] = nil
end
table.clear(MotorList)
end
end)