@quenty/ragdoll 15.51.1 → 15.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- --!nonstrict
1
+ --!strict
2
2
  --[=[
3
3
  Ragdolls the humanoid on fall. This is the base class.
4
4
  @class BindableRagdollHumanoidOnFall
@@ -7,6 +7,7 @@
7
7
  local require = require(script.Parent.loader).load(script)
8
8
 
9
9
  local BaseObject = require("BaseObject")
10
+ local Observable = require("Observable")
10
11
  local ValueObject = require("ValueObject")
11
12
 
12
13
  local FRAMES_TO_EXAMINE = 8
@@ -18,14 +19,28 @@ local BindableRagdollHumanoidOnFall = setmetatable({}, BaseObject)
18
19
  BindableRagdollHumanoidOnFall.ClassName = "BindableRagdollHumanoidOnFall"
19
20
  BindableRagdollHumanoidOnFall.__index = BindableRagdollHumanoidOnFall
20
21
 
22
+ export type BindableRagdollHumanoidOnFall =
23
+ typeof(setmetatable(
24
+ {} :: {
25
+ _ragdollBinder: any, -- Binder.Binder<Ragdoll | RagdollClient> (heavy cyclic binder; old solver can't hold it)
26
+ ShouldRagdoll: ValueObject.ValueObject<boolean>,
27
+ _isFalling: ValueObject.ValueObject<boolean>,
28
+ _lastVelocityRecords: { Vector3 },
29
+ _lastRagDollTime: number,
30
+ },
31
+ {} :: typeof({ __index = BindableRagdollHumanoidOnFall })
32
+ ))
33
+ & BaseObject.BaseObject
34
+
21
35
  --[=[
22
36
  Constructs a new BindableRagdollHumanoidOnFall.
23
37
  @param humanoid Humanoid
24
38
  @param ragdollBinder Binder<Ragdoll | RagdollClient>
25
39
  @return BindableRagdollHumanoidOnFall
26
40
  ]=]
27
- function BindableRagdollHumanoidOnFall.new(humanoid: Humanoid, ragdollBinder)
28
- local self = setmetatable(BaseObject.new(humanoid), BindableRagdollHumanoidOnFall)
41
+ function BindableRagdollHumanoidOnFall.new(humanoid: Humanoid, ragdollBinder: any): BindableRagdollHumanoidOnFall
42
+ local self: BindableRagdollHumanoidOnFall =
43
+ setmetatable(BaseObject.new(humanoid) :: any, BindableRagdollHumanoidOnFall)
29
44
 
30
45
  self._ragdollBinder = assert(ragdollBinder, "Bad ragdollBinder")
31
46
 
@@ -60,22 +75,24 @@ function BindableRagdollHumanoidOnFall.new(humanoid: Humanoid, ragdollBinder)
60
75
  return self
61
76
  end
62
77
 
63
- function BindableRagdollHumanoidOnFall:ObserveIsFalling()
78
+ function BindableRagdollHumanoidOnFall.ObserveIsFalling(
79
+ self: BindableRagdollHumanoidOnFall
80
+ ): Observable.Observable<boolean>
64
81
  return self._isFalling:Observe()
65
82
  end
66
83
 
67
- function BindableRagdollHumanoidOnFall:_initLastVelocityRecords()
84
+ function BindableRagdollHumanoidOnFall._initLastVelocityRecords(self: BindableRagdollHumanoidOnFall): ()
68
85
  self._lastVelocityRecords = {}
69
86
  for _ = 1, FRAMES_TO_EXAMINE + 1 do -- Add an extra frame because we remove before inserting
70
87
  table.insert(self._lastVelocityRecords, Vector3.zero)
71
88
  end
72
89
  end
73
90
 
74
- function BindableRagdollHumanoidOnFall:_getLargestSpeedInRecords()
91
+ function BindableRagdollHumanoidOnFall._getLargestSpeedInRecords(self: BindableRagdollHumanoidOnFall): number
75
92
  local largestSpeed = -math.huge
76
93
 
77
94
  for _, velocityRecord in self._lastVelocityRecords do
78
- local speed = velocityRecord.magnitude
95
+ local speed = velocityRecord.Magnitude
79
96
  if speed > largestSpeed then
80
97
  largestSpeed = speed
81
98
  end
@@ -84,7 +101,7 @@ function BindableRagdollHumanoidOnFall:_getLargestSpeedInRecords()
84
101
  return largestSpeed
85
102
  end
86
103
 
87
- function BindableRagdollHumanoidOnFall:_ragdollFromFall()
104
+ function BindableRagdollHumanoidOnFall._ragdollFromFall(self: BindableRagdollHumanoidOnFall): ()
88
105
  self.ShouldRagdoll.Value = true
89
106
 
90
107
  task.spawn(function()
@@ -96,34 +113,34 @@ function BindableRagdollHumanoidOnFall:_ragdollFromFall()
96
113
  task.wait(0.75)
97
114
  end
98
115
 
99
- if self.Destroy and self._obj.Health > 0 then
116
+ if self.Destroy and (self._obj :: Humanoid).Health > 0 then
100
117
  self.ShouldRagdoll.Value = false
101
118
  end
102
119
  end)
103
120
  end
104
121
 
105
- function BindableRagdollHumanoidOnFall:_updateVelocity()
122
+ function BindableRagdollHumanoidOnFall._updateVelocity(self: BindableRagdollHumanoidOnFall): ()
106
123
  table.remove(self._lastVelocityRecords, 1)
107
124
 
108
- local rootPart = self._obj.RootPart
125
+ local rootPart = (self._obj :: Humanoid).RootPart
109
126
  if not rootPart then
110
127
  self._isFalling.Value = false
111
128
  table.insert(self._lastVelocityRecords, Vector3.zero)
112
129
  return
113
130
  end
114
131
 
115
- local currentVelocity = rootPart.Velocity
132
+ local currentVelocity = (rootPart :: any).Velocity :: Vector3
116
133
 
117
134
  local fellForAllFrames = true
118
135
  local mostNegativeVelocityY = math.huge
119
136
  for _, velocityRecord in self._lastVelocityRecords do
120
- if velocityRecord.y >= -2 then
137
+ if velocityRecord.Y >= -2 then
121
138
  fellForAllFrames = false
122
139
  break
123
140
  end
124
141
 
125
- if velocityRecord.y < mostNegativeVelocityY then
126
- mostNegativeVelocityY = velocityRecord.y
142
+ if velocityRecord.Y < mostNegativeVelocityY then
143
+ mostNegativeVelocityY = velocityRecord.Y
127
144
  end
128
145
  end
129
146
 
@@ -144,15 +161,15 @@ function BindableRagdollHumanoidOnFall:_updateVelocity()
144
161
 
145
162
  -- print("currentVelocity.magnitude, mostNegativeVelocityY", currentVelocity.magnitude, mostNegativeVelocityY)
146
163
 
147
- if self._obj.Health <= 0 then
164
+ if (self._obj :: Humanoid).Health <= 0 then
148
165
  return
149
166
  end
150
167
 
151
- if self._obj.Sit then
168
+ if (self._obj :: Humanoid).Sit then
152
169
  return
153
170
  end
154
171
 
155
- local currentState = self._obj:GetState()
172
+ local currentState = (self._obj :: Humanoid):GetState()
156
173
  if currentState == Enum.HumanoidStateType.Physics or currentState == Enum.HumanoidStateType.Swimming then
157
174
  return
158
175
  end
@@ -1,4 +1,4 @@
1
- --!nonstrict
1
+ --!strict
2
2
  --[=[
3
3
  @class RagdollableBase
4
4
  ]=]
@@ -6,6 +6,7 @@
6
6
  local require = require(script.Parent.loader).load(script)
7
7
 
8
8
  local BaseObject = require("BaseObject")
9
+ local Observable = require("Observable")
9
10
  local Rx = require("Rx")
10
11
  local RxSignal = require("RxSignal")
11
12
 
@@ -13,44 +14,54 @@ local RagdollableBase = setmetatable({}, BaseObject)
13
14
  RagdollableBase.ClassName = "RagdollableBase"
14
15
  RagdollableBase.__index = RagdollableBase
15
16
 
16
- function RagdollableBase.new(humanoid: Humanoid)
17
- local self = setmetatable(BaseObject.new(humanoid), RagdollableBase)
17
+ export type RagdollableBase =
18
+ typeof(setmetatable(
19
+ {} :: {
20
+ Ragdolled: RxSignal.RxSignal<boolean>,
21
+ Unragdolled: RxSignal.RxSignal<boolean>,
22
+ },
23
+ {} :: typeof({ __index = RagdollableBase })
24
+ ))
25
+ & BaseObject.BaseObject
18
26
 
19
- self.Ragdolled = RxSignal.new(function()
20
- return self:ObserveIsRagdolled():Pipe({
27
+ function RagdollableBase.new(humanoid: Humanoid): RagdollableBase
28
+ local self: RagdollableBase = setmetatable(BaseObject.new(humanoid) :: any, RagdollableBase)
29
+
30
+ self.Ragdolled = RxSignal.new(function(): any
31
+ return (self:ObserveIsRagdolled() :: any):Pipe({
21
32
  Rx.skip(1),
22
- Rx.where(function(value)
33
+ Rx.where(function(value): any
23
34
  return value == true
24
35
  end),
25
36
  })
26
- end)
37
+ end) :: any
27
38
 
28
- self.Unragdolled = RxSignal.new(function()
29
- return self:ObserveIsRagdolled():Pipe({
39
+ self.Unragdolled = RxSignal.new(function(): any
40
+ return (self:ObserveIsRagdolled() :: any):Pipe({
30
41
  Rx.skip(1),
31
- Rx.where(function(value)
42
+ Rx.where(function(value): any
32
43
  return value == true
33
44
  end),
34
45
  })
35
- end)
46
+ end) :: any
36
47
 
37
48
  return self
38
49
  end
39
50
 
40
- function RagdollableBase:Ragdoll()
41
- self._obj:AddTag("Ragdoll")
51
+ function RagdollableBase.Ragdoll(self: RagdollableBase): ()
52
+ (self._obj :: Instance):AddTag("Ragdoll")
42
53
  end
43
54
 
44
- function RagdollableBase:Unragdoll()
45
- self._obj:RemoveTag("Ragdoll")
55
+ function RagdollableBase.Unragdoll(self: RagdollableBase): ()
56
+ (self._obj :: Instance):RemoveTag("Ragdoll")
46
57
  end
47
58
 
48
- function RagdollableBase:ObserveIsRagdolled()
49
- error("Not implemented")
59
+ function RagdollableBase.ObserveIsRagdolled(_self: RagdollableBase): Observable.Observable<boolean>
60
+ return error("Not implemented")
50
61
  end
51
62
 
52
- function RagdollableBase:IsRagdolled(): boolean
53
- return self._obj:HasTag("Ragdoll")
63
+ function RagdollableBase.IsRagdolled(self: RagdollableBase): boolean
64
+ return (self._obj :: Instance):HasTag("Ragdoll")
54
65
  end
55
66
 
56
67
  return RagdollableBase
@@ -1,4 +1,4 @@
1
- --!nonstrict
1
+ --!strict
2
2
  --[=[
3
3
  @class RagdollAdditionalAttachmentUtils
4
4
  ]=]
@@ -23,7 +23,7 @@ local V3_LEFT = Vector3.new(-1, 0, 0)
23
23
  -- to be going down the limb. the waist and neck joints attachments actually have the same problem
24
24
  -- of non-ideal axis orientation, but it's not as noticable there since the limits for natural
25
25
  -- motion are tighter for those joints anyway.
26
- local R15_ADDITIONAL_ATTACHMENTS = {
26
+ local R15_ADDITIONAL_ATTACHMENTS: { { any } } = {
27
27
  {
28
28
  "UpperTorso",
29
29
  "RightShoulderRagdollAttachment",
@@ -50,7 +50,7 @@ local R15_ADDITIONAL_ATTACHMENTS = {
50
50
  },
51
51
  }
52
52
 
53
- local R6_ADDITIONAL_ATTACHMENTS = {
53
+ local R6_ADDITIONAL_ATTACHMENTS: { { any } } = {
54
54
  { "Head", "NeckAttachment", CFrame.new(0, -0.5, 0) },
55
55
  { "Torso", "NeckAttachment", CFrame.new(0, 1, 0) },
56
56
 
@@ -67,7 +67,7 @@ local R6_ADDITIONAL_ATTACHMENTS = {
67
67
  { "Left Leg", "LeftHipAttachment", CFrame.new(0, 1, 0) },
68
68
  }
69
69
 
70
- function RagdollAdditionalAttachmentUtils.getAdditionalAttachmentData(rigType)
70
+ function RagdollAdditionalAttachmentUtils.getAdditionalAttachmentData(rigType: Enum.HumanoidRigType): { { any } }
71
71
  if rigType == Enum.HumanoidRigType.R15 then
72
72
  return R15_ADDITIONAL_ATTACHMENTS
73
73
  elseif rigType == Enum.HumanoidRigType.R6 then
@@ -77,7 +77,10 @@ function RagdollAdditionalAttachmentUtils.getAdditionalAttachmentData(rigType)
77
77
  end
78
78
  end
79
79
 
80
- function RagdollAdditionalAttachmentUtils.ensureAdditionalAttachments(character, rigType)
80
+ function RagdollAdditionalAttachmentUtils.ensureAdditionalAttachments(
81
+ character: Model,
82
+ rigType: Enum.HumanoidRigType
83
+ ): Maid.Maid
81
84
  assert(typeof(character) == "Instance" and character:IsA("Model"), "Bad character")
82
85
  assert(EnumUtils.isOfType(Enum.HumanoidRigType, rigType), "Bad rigType")
83
86
 
@@ -90,9 +93,9 @@ function RagdollAdditionalAttachmentUtils.ensureAdditionalAttachments(character,
90
93
  local observable = RxBrioUtils.flatCombineLatest({
91
94
  part = RxR15Utils.observeCharacterPartBrio(character, partName),
92
95
  baseAttachment = RxR15Utils.observeRigAttachmentBrio(character, partName, baseAttachmentName),
93
- })
96
+ }) :: any
94
97
 
95
- topMaid:GiveTask(observable:Subscribe(function(state)
98
+ topMaid:GiveTask(observable:Subscribe(function(state: any)
96
99
  if state.part and state.baseAttachment then
97
100
  local maid = Maid.new()
98
101
 
@@ -114,20 +117,22 @@ function RagdollAdditionalAttachmentUtils.ensureAdditionalAttachments(character,
114
117
  end
115
118
  end))
116
119
  else
117
- topMaid:GiveTask(RxR15Utils.observeCharacterPartBrio(character, partName):Subscribe(function(brio)
118
- if brio:IsDead() then
119
- return
120
- end
120
+ topMaid:GiveTask(
121
+ (RxR15Utils.observeCharacterPartBrio(character, partName) :: any):Subscribe(function(brio: any)
122
+ if brio:IsDead() then
123
+ return
124
+ end
121
125
 
122
- local maid = brio:ToMaid()
123
- local part = brio:GetValue()
126
+ local maid = brio:ToMaid()
127
+ local part = brio:GetValue()
124
128
 
125
- local attachment = Instance.new("Attachment")
126
- attachment.Name = attachmentName
127
- attachment.CFrame = cframe
128
- attachment.Parent = part
129
- maid:GiveTask(attachment)
130
- end))
129
+ local attachment = Instance.new("Attachment")
130
+ attachment.Name = attachmentName
131
+ attachment.CFrame = cframe
132
+ attachment.Parent = part
133
+ maid:GiveTask(attachment)
134
+ end)
135
+ )
131
136
  end
132
137
  end
133
138
 
@@ -1,4 +1,4 @@
1
- --!nonstrict
1
+ --!strict
2
2
  --[=[
3
3
  Instead of modifying this file, consider setting attributes on each motor on humanoid
4
4
  join.
@@ -21,7 +21,16 @@ local RxR15Utils = require("RxR15Utils")
21
21
 
22
22
  local RagdollBallSocketUtils = {}
23
23
 
24
- local R6_RAGDOLL_RIG = {
24
+ export type RagdollRigData = {
25
+ part0Name: string,
26
+ part1Name: string,
27
+ attachmentName: string,
28
+ motorParentName: string,
29
+ motorName: string,
30
+ limitData: any,
31
+ }
32
+
33
+ local R6_RAGDOLL_RIG: { RagdollRigData } = {
25
34
  {
26
35
  part0Name = "Torso",
27
36
  part1Name = "Head",
@@ -64,7 +73,7 @@ local R6_RAGDOLL_RIG = {
64
73
  },
65
74
  }
66
75
 
67
- local R15_RAGDOLL_RIG = {
76
+ local R15_RAGDOLL_RIG: { RagdollRigData } = {
68
77
  {
69
78
  part0Name = "UpperTorso",
70
79
  part1Name = "Head",
@@ -181,7 +190,7 @@ local R15_RAGDOLL_RIG = {
181
190
  },
182
191
  }
183
192
 
184
- function RagdollBallSocketUtils.getRigData(rigType)
193
+ function RagdollBallSocketUtils.getRigData(rigType: Enum.HumanoidRigType): { RagdollRigData }
185
194
  if rigType == Enum.HumanoidRigType.R15 then
186
195
  return R15_RAGDOLL_RIG
187
196
  elseif rigType == Enum.HumanoidRigType.R6 then
@@ -191,7 +200,7 @@ function RagdollBallSocketUtils.getRigData(rigType)
191
200
  end
192
201
  end
193
202
 
194
- function RagdollBallSocketUtils.ensureBallSockets(character, rigType)
203
+ function RagdollBallSocketUtils.ensureBallSockets(character: Model, rigType: Enum.HumanoidRigType): Maid.Maid
195
204
  assert(typeof(character) == "Instance" and character:IsA("Model"), "Bad character")
196
205
  assert(EnumUtils.isOfType(Enum.HumanoidRigType, rigType), "Bad rigType")
197
206
 
@@ -204,7 +213,7 @@ function RagdollBallSocketUtils.ensureBallSockets(character, rigType)
204
213
  local attachmentName = assert(data.attachmentName, "No attachmentName")
205
214
  local limitData = assert(data.limitData, "No limits")
206
215
 
207
- local observable = RxR15Utils.observeRigMotorBrio(character, data.motorParentName, motorName):Pipe({
216
+ local observable = (RxR15Utils.observeRigMotorBrio(character, data.motorParentName, motorName) :: any):Pipe({
208
217
  RxBrioUtils.switchMapBrio(function(motor)
209
218
  if motor then
210
219
  return RxBrioUtils.flatCombineLatest({
@@ -217,15 +226,15 @@ function RagdollBallSocketUtils.ensureBallSockets(character, rigType)
217
226
  else
218
227
  return Rx.of({})
219
228
  end
220
- end),
221
- RxBrioUtils.where(function(motorState)
229
+ end) :: any,
230
+ RxBrioUtils.where(function(motorState: any)
222
231
  return motorState.attachment0
223
232
  and motorState.attachment1
224
233
  and motorState.part1
225
234
  and motorState.motor
226
235
  and true
227
236
  or false
228
- end),
237
+ end) :: any,
229
238
  })
230
239
 
231
240
  topMaid:GiveTask(observable:Subscribe(function(brio)
@@ -263,7 +272,7 @@ function RagdollBallSocketUtils.ensureBallSockets(character, rigType)
263
272
  referenceMass = limitValue.ReferenceMass:Observe(),
264
273
  gravity = RxInstanceUtils.observeProperty(Workspace, "Gravity"),
265
274
  mass = RxPhysicsUtils.observePartMass(motorState.part1),
266
- }):Subscribe(function(state)
275
+ }):Subscribe(function(state: any)
267
276
  local gravityScale = state.gravity / state.referenceGravity
268
277
  local referenceMass = state.referenceMass
269
278
  local massScale = referenceMass and (state.mass / referenceMass) or 1
@@ -1,4 +1,4 @@
1
- --!nonstrict
1
+ --!strict
2
2
  --[=[
3
3
  @class RagdollCollisionUtils
4
4
  ]=]
@@ -12,7 +12,7 @@ local RxR15Utils = require("RxR15Utils")
12
12
 
13
13
  local RagdollCollisionUtils = {}
14
14
 
15
- local R15_NO_COLLIDES = {
15
+ local R15_NO_COLLIDES: { { string } } = {
16
16
  { "LowerTorso", "LeftUpperArm" },
17
17
  { "LeftUpperArm", "LeftHand" },
18
18
 
@@ -57,7 +57,7 @@ local R15_NO_COLLIDES = {
57
57
  { "HumanoidRootPart", "LowerTorso" },
58
58
  }
59
59
 
60
- local R15_PARTS = {
60
+ local R15_PARTS: { string } = {
61
61
  "LeftUpperArm",
62
62
  "RightUpperArm",
63
63
  "LeftLowerArm",
@@ -75,7 +75,7 @@ local R15_PARTS = {
75
75
  "LowerTorso",
76
76
  }
77
77
 
78
- local R6_NO_COLLIDES = {
78
+ local R6_NO_COLLIDES: { { string } } = {
79
79
  { "Left Leg", "Right Leg" },
80
80
  { "Head", "Right Arm" },
81
81
  { "Head", "Left Arm" },
@@ -87,7 +87,7 @@ local R6_NO_COLLIDES = {
87
87
  { "HumanoidRootPart", "Left Arm" },
88
88
  }
89
89
 
90
- function RagdollCollisionUtils.getCollisionData(rigType: Enum.HumanoidRigType)
90
+ function RagdollCollisionUtils.getCollisionData(rigType: Enum.HumanoidRigType): { { string } }
91
91
  if rigType == Enum.HumanoidRigType.R15 then
92
92
  return R15_NO_COLLIDES
93
93
  elseif rigType == Enum.HumanoidRigType.R6 then
@@ -97,11 +97,11 @@ function RagdollCollisionUtils.getCollisionData(rigType: Enum.HumanoidRigType)
97
97
  end
98
98
  end
99
99
 
100
- function RagdollCollisionUtils.preventCollisionAmongOthers(character: Model, part: BasePart)
100
+ function RagdollCollisionUtils.preventCollisionAmongOthers(character: Model, part: BasePart): Maid.Maid
101
101
  local topMaid = Maid.new()
102
102
 
103
103
  for _, partName in R15_PARTS do
104
- topMaid:GiveTask(RxR15Utils.observeCharacterPartBrio(character, partName):Subscribe(function(brio)
104
+ topMaid:GiveTask((RxR15Utils.observeCharacterPartBrio(character, partName) :: any):Subscribe(function(brio: any)
105
105
  if brio:IsDead() then
106
106
  return
107
107
  end
@@ -121,7 +121,7 @@ function RagdollCollisionUtils.preventCollisionAmongOthers(character: Model, par
121
121
  return topMaid
122
122
  end
123
123
 
124
- function RagdollCollisionUtils.ensureNoCollides(character: Model, rigType: Enum.HumanoidRigType)
124
+ function RagdollCollisionUtils.ensureNoCollides(character: Model, rigType: Enum.HumanoidRigType): Maid.Maid
125
125
  assert(typeof(character) == "Instance" and character:IsA("Model"), "Bad character")
126
126
  assert(EnumUtils.isOfType(Enum.HumanoidRigType, rigType), "Bad rigType")
127
127
 
@@ -133,9 +133,9 @@ function RagdollCollisionUtils.ensureNoCollides(character: Model, rigType: Enum.
133
133
  local observable = RxBrioUtils.flatCombineLatest({
134
134
  part0 = RxR15Utils.observeCharacterPartBrio(character, part0Name),
135
135
  part1 = RxR15Utils.observeCharacterPartBrio(character, part1Name),
136
- })
136
+ }) :: any
137
137
 
138
- topMaid:GiveTask(observable:Subscribe(function(state)
138
+ topMaid:GiveTask(observable:Subscribe(function(state: any)
139
139
  if state.part0 and state.part1 then
140
140
  local maid = Maid.new()
141
141
 
@@ -1,4 +1,4 @@
1
- --!nonstrict
1
+ --!strict
2
2
  --[=[
3
3
  Holds baseline constants for the Ragdoll
4
4
 
@@ -1,4 +1,4 @@
1
- --!nonstrict
1
+ --!strict
2
2
  --[=[
3
3
  @class RagdollMotorUtils
4
4
  ]=]
@@ -33,6 +33,19 @@ type MotorData = {
33
33
 
34
34
  type MotorDataList = { MotorData }
35
35
 
36
+ type VelocityReadings = {
37
+ readingTimePhysics: number,
38
+ linear: { [MotorData]: Vector3 },
39
+ rotation: { [MotorData]: Vector3 },
40
+ }
41
+
42
+ type MotorPartInfo = {
43
+ motor: Motor6D,
44
+ part0: BasePart,
45
+ part1: BasePart,
46
+ relCFrame: CFrame,
47
+ }
48
+
36
49
  local R6_MOTORS: MotorDataList = {
37
50
  {
38
51
  partName = "Torso",
@@ -125,7 +138,7 @@ local R15_MOTORS: MotorDataList = {
125
138
  },
126
139
  }
127
140
 
128
- local ROOT_JOINT_CACHE = {}
141
+ local ROOT_JOINT_CACHE: { [Enum.HumanoidRigType]: MotorData } = {}
129
142
 
130
143
  function RagdollMotorUtils.getFirstRootJointData(rigType: Enum.HumanoidRigType): MotorData
131
144
  if ROOT_JOINT_CACHE[rigType] then
@@ -152,7 +165,7 @@ function RagdollMotorUtils.getMotorData(rigType: Enum.HumanoidRigType): MotorDat
152
165
  end
153
166
  end
154
167
 
155
- function RagdollMotorUtils.initMotorAttributes(character, rigType: Enum.HumanoidRigType)
168
+ function RagdollMotorUtils.initMotorAttributes(character: Model, rigType: Enum.HumanoidRigType): ()
156
169
  assert(typeof(character) == "Instance" and character:IsA("Model"), "Bad character")
157
170
  assert(EnumUtils.isOfType(Enum.HumanoidRigType, rigType), "Bad rigType")
158
171
 
@@ -164,7 +177,7 @@ function RagdollMotorUtils.initMotorAttributes(character, rigType: Enum.Humanoid
164
177
  end
165
178
  end
166
179
 
167
- function RagdollMotorUtils.setupAnimatedMotor(character: Model, part: BasePart)
180
+ function RagdollMotorUtils.setupAnimatedMotor(character: Model, part: BasePart): Maid.Maid
168
181
  local maid = Maid.new()
169
182
 
170
183
  -- make this stuff not physics collide with our own rig
@@ -174,7 +187,7 @@ function RagdollMotorUtils.setupAnimatedMotor(character: Model, part: BasePart)
174
187
  return maid
175
188
  end
176
189
 
177
- function RagdollMotorUtils.setupRagdollRootPartMotor(motor: Motor6D, part0, part1)
190
+ function RagdollMotorUtils.setupRagdollRootPartMotor(motor: Motor6D, part0: BasePart, part1: BasePart): Maid.Maid
178
191
  local maid = Maid.new()
179
192
 
180
193
  local ragdollMotorData = RagdollMotorData:Create(motor)
@@ -191,10 +204,10 @@ function RagdollMotorUtils.setupRagdollRootPartMotor(motor: Motor6D, part0, part
191
204
  weldContainer.Name = "TempWeldContainer"
192
205
  weldContainer.Parent = part0
193
206
 
194
- local function setupWeld(weldType)
207
+ local function setupWeld(weldType: string): Maid.Maid
195
208
  local weldMaid = Maid.new()
196
209
 
197
- local weld = Instance.new(weldType)
210
+ local weld = Instance.new(weldType :: any) :: any
198
211
  weld.Name = "TempRagdollWeld"
199
212
  weld.Part0 = part0
200
213
  weld.Part1 = part1
@@ -204,7 +217,7 @@ function RagdollMotorUtils.setupRagdollRootPartMotor(motor: Motor6D, part0, part
204
217
  weldMaid:GiveTask(Rx.combineLatest({
205
218
  C0 = RxInstanceUtils.observeProperty(motor, "C0"),
206
219
  Transform = RxInstanceUtils.observeProperty(transformValue, "Value"),
207
- }):Subscribe(function(innerState)
220
+ }):Subscribe(function(innerState: any)
208
221
  weld.C0 = innerState.C0 * innerState.Transform
209
222
  end))
210
223
 
@@ -256,7 +269,7 @@ function RagdollMotorUtils.setupRagdollRootPartMotor(motor: Motor6D, part0, part
256
269
  return maid
257
270
  end
258
271
 
259
- function RagdollMotorUtils.setupRagdollMotor(motor: Motor6D, part0: BasePart, part1: BasePart)
272
+ function RagdollMotorUtils.setupRagdollMotor(motor: Motor6D, part0: BasePart, part1: BasePart): Maid.Maid
260
273
  local maid = Maid.new()
261
274
 
262
275
  motor.Enabled = false
@@ -280,11 +293,11 @@ function RagdollMotorUtils.setupRagdollMotor(motor: Motor6D, part0: BasePart, pa
280
293
  return maid
281
294
  end
282
295
 
283
- function RagdollMotorUtils.suppressJustRootPart(character: Model, rigType: Enum.HumanoidRigType)
296
+ function RagdollMotorUtils.suppressJustRootPart(character: Model, rigType: Enum.HumanoidRigType): Maid.Maid
284
297
  local data = RagdollMotorUtils.getFirstRootJointData(rigType)
285
298
 
286
- local observable = RxR15Utils.observeRigMotorBrio(character, data.partName, data.motorName):Pipe({
287
- RxBrioUtils.switchMapBrio(function(motor)
299
+ local observable: any = (RxR15Utils.observeRigMotorBrio(character, data.partName, data.motorName) :: any):Pipe({
300
+ RxBrioUtils.switchMapBrio(function(motor): any
288
301
  local ragdollMotorData = RagdollMotorData:Create(motor)
289
302
 
290
303
  return Rx.combineLatest({
@@ -320,15 +333,19 @@ function RagdollMotorUtils.suppressJustRootPart(character: Model, rigType: Enum.
320
333
  return topMaid
321
334
  end
322
335
 
323
- function RagdollMotorUtils.suppressMotors(character: Model, rigType: Enum.HumanoidRigType, velocityReadings)
336
+ function RagdollMotorUtils.suppressMotors(
337
+ character: Model,
338
+ rigType: Enum.HumanoidRigType,
339
+ velocityReadings: VelocityReadings
340
+ ): Maid.Maid
324
341
  assert(typeof(character) == "Instance" and character:IsA("Model"), "Bad character")
325
342
  assert(EnumUtils.isOfType(Enum.HumanoidRigType, rigType), "Bad rigType")
326
343
 
327
344
  local topMaid = Maid.new()
328
345
 
329
346
  for _, data in RagdollMotorUtils.getMotorData(rigType) do
330
- local observable = RxR15Utils.observeRigMotorBrio(character, data.partName, data.motorName):Pipe({
331
- RxBrioUtils.switchMapBrio(function(motor)
347
+ local observable: any = (RxR15Utils.observeRigMotorBrio(character, data.partName, data.motorName) :: any):Pipe({
348
+ RxBrioUtils.switchMapBrio(function(motor): any
332
349
  local ragdollMotorData = RagdollMotorData:Create(motor)
333
350
 
334
351
  return RxBrioUtils.flatCombineLatest({
@@ -389,7 +406,7 @@ function RagdollMotorUtils.suppressMotors(character: Model, rigType: Enum.Humano
389
406
  end
390
407
 
391
408
  function RagdollMotorUtils.guessIfNetworkOwner(part: BasePart): boolean
392
- local currentNetworkOwner
409
+ local currentNetworkOwner: Player?
393
410
  local expectedNetworkOwner = Players.LocalPlayer
394
411
 
395
412
  -- hopefully someday GetNetworkOwner() works on the client.
@@ -407,11 +424,14 @@ function RagdollMotorUtils.guessIfNetworkOwner(part: BasePart): boolean
407
424
  return CharacterUtils.getPlayerFromCharacter(part) == expectedNetworkOwner
408
425
  end
409
426
 
410
- function RagdollMotorUtils.promiseVelocityRecordings(character: Model, rigType: Enum.HumanoidRigType)
427
+ function RagdollMotorUtils.promiseVelocityRecordings(
428
+ character: Model,
429
+ rigType: Enum.HumanoidRigType
430
+ ): Promise.Promise<VelocityReadings>
411
431
  assert(typeof(character) == "Instance" and character:IsA("Model"), "Bad character")
412
432
  assert(EnumUtils.isOfType(Enum.HumanoidRigType, rigType), "Bad rigType")
413
433
 
414
- local parts = {}
434
+ local parts: { [MotorData]: MotorPartInfo } = {}
415
435
 
416
436
  local rootPart = character:FindFirstChild("HumanoidRootPart")
417
437
  if rootPart == nil or not rootPart:IsA("BasePart") then
@@ -420,7 +440,7 @@ function RagdollMotorUtils.promiseVelocityRecordings(character: Model, rigType:
420
440
 
421
441
  local initialRootPartCFrame = rootPart.CFrame
422
442
  for _, data in RagdollMotorUtils.getMotorData(rigType) do
423
- local motor = R15Utils.getRigMotor(character, data.partName, data.motorName)
443
+ local motor = R15Utils.getRigMotor(character, data.partName, data.motorName) :: Motor6D?
424
444
  if motor then
425
445
  local part0 = motor.Part0
426
446
  local part1 = motor.Part1
@@ -442,14 +462,14 @@ function RagdollMotorUtils.promiseVelocityRecordings(character: Model, rigType:
442
462
  -- physics data
443
463
  local newRootPartCFrame = rootPart.CFrame
444
464
 
445
- local result = {
465
+ local result: VelocityReadings = {
446
466
  readingTimePhysics = time(),
447
467
  linear = {},
448
468
  rotation = {},
449
469
  }
450
470
 
451
471
  for data, info in parts do
452
- local motor = R15Utils.getRigMotor(character, data.partName, data.motorName)
472
+ local motor = R15Utils.getRigMotor(character, data.partName, data.motorName) :: Motor6D?
453
473
 
454
474
  -- Validate all the same
455
475
  if motor ~= nil and info.motor == motor and info.part0 == motor.Part0 and info.part1 == motor.Part1 then
@@ -470,9 +490,9 @@ function RagdollMotorUtils.promiseVelocityRecordings(character: Model, rigType:
470
490
  end)
471
491
  end
472
492
 
473
- function RagdollMotorUtils.yieldUntilStepped()
493
+ function RagdollMotorUtils.yieldUntilStepped(): number
474
494
  local start = time()
475
- local dt
495
+ local dt: number
476
496
  repeat
477
497
  -- Apparently this is an issue...
478
498
  RunService.Stepped:Wait()