@quenty/physicsutils 8.16.0 → 8.16.1
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.
- package/CHANGELOG.md +8 -0
- package/package.json +3 -3
- package/src/Shared/PhysicsUtils.lua +28 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.16.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/physicsutils@8.16.0...@quenty/physicsutils@8.16.1) (2025-03-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/physicsutils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [8.16.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/physicsutils@8.15.0...@quenty/physicsutils@8.16.0) (2025-02-18)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/physicsutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/physicsutils",
|
|
3
|
-
"version": "8.16.
|
|
3
|
+
"version": "8.16.1",
|
|
4
4
|
"description": "General physics library for use on Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@quenty/loader": "^10.8.0",
|
|
32
32
|
"@quenty/maid": "^3.4.0",
|
|
33
|
-
"@quenty/rx": "^13.16.
|
|
33
|
+
"@quenty/rx": "^13.16.1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "6b7c3e15e60cdb185986207b574e2b5591261e7a"
|
|
36
36
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
General physics library for use on Roblox
|
|
3
4
|
@class PhysicsUtils
|
|
@@ -13,9 +14,9 @@ PhysicsUtils.WATER_DENSITY = 1 -- (mass/volume)
|
|
|
13
14
|
@param part BasePart
|
|
14
15
|
@return { BasePart }
|
|
15
16
|
]=]
|
|
16
|
-
function PhysicsUtils.getConnectedParts(part)
|
|
17
|
-
local parts = part:GetConnectedParts(true)
|
|
18
|
-
parts
|
|
17
|
+
function PhysicsUtils.getConnectedParts(part: BasePart): { BasePart }
|
|
18
|
+
local parts: { BasePart } = part:GetConnectedParts(true) :: any
|
|
19
|
+
table.insert(parts, part)
|
|
19
20
|
return parts
|
|
20
21
|
end
|
|
21
22
|
|
|
@@ -24,9 +25,9 @@ end
|
|
|
24
25
|
@param parts { BasePart }
|
|
25
26
|
@return number
|
|
26
27
|
]=]
|
|
27
|
-
function PhysicsUtils.getMass(parts)
|
|
28
|
+
function PhysicsUtils.getMass(parts: { BasePart }): number
|
|
28
29
|
local mass = 0
|
|
29
|
-
for _, part in
|
|
30
|
+
for _, part in parts do
|
|
30
31
|
mass = mass + part:GetMass()
|
|
31
32
|
end
|
|
32
33
|
return mass
|
|
@@ -39,19 +40,19 @@ end
|
|
|
39
40
|
@return number -- mass
|
|
40
41
|
@return number -- volume
|
|
41
42
|
]=]
|
|
42
|
-
function PhysicsUtils.estimateBuoyancyContribution(parts)
|
|
43
|
+
function PhysicsUtils.estimateBuoyancyContribution(parts: { BasePart }): (number, number, number)
|
|
43
44
|
local totalMass = 0
|
|
44
45
|
local totalVolumeApplicable = 0
|
|
45
46
|
local totalFloat = 0
|
|
46
47
|
|
|
47
|
-
for _, part in
|
|
48
|
+
for _, part in parts do
|
|
48
49
|
local mass = part:GetMass()
|
|
49
50
|
totalMass = totalMass + mass
|
|
50
51
|
totalFloat = totalFloat - mass * Workspace.Gravity
|
|
51
52
|
|
|
52
53
|
if part.CanCollide then
|
|
53
|
-
local volume = part.Size.X*part.Size.Y*part.Size.Z
|
|
54
|
-
totalFloat = totalFloat + volume*PhysicsUtils.WATER_DENSITY*Workspace.Gravity
|
|
54
|
+
local volume = part.Size.X * part.Size.Y * part.Size.Z
|
|
55
|
+
totalFloat = totalFloat + volume * PhysicsUtils.WATER_DENSITY * Workspace.Gravity
|
|
55
56
|
totalVolumeApplicable = totalVolumeApplicable + volume
|
|
56
57
|
end
|
|
57
58
|
end
|
|
@@ -65,16 +66,16 @@ end
|
|
|
65
66
|
@return Vector3 -- position
|
|
66
67
|
@return number -- mass
|
|
67
68
|
]=]
|
|
68
|
-
function PhysicsUtils.getCenterOfMass(parts)
|
|
69
|
+
function PhysicsUtils.getCenterOfMass(parts: { BasePart }): (Vector3, number)
|
|
69
70
|
local mass = 0
|
|
70
71
|
local weightedSum = Vector3.zero
|
|
71
72
|
|
|
72
|
-
for _, part in
|
|
73
|
+
for _, part in parts do
|
|
73
74
|
mass = mass + part:GetMass()
|
|
74
75
|
weightedSum = weightedSum + part:GetMass() * part.Position
|
|
75
76
|
end
|
|
76
77
|
|
|
77
|
-
return weightedSum/mass, mass
|
|
78
|
+
return weightedSum / mass, mass
|
|
78
79
|
end
|
|
79
80
|
|
|
80
81
|
--[=[
|
|
@@ -89,19 +90,19 @@ end
|
|
|
89
90
|
@param origin Vector3
|
|
90
91
|
@return number
|
|
91
92
|
]=]
|
|
92
|
-
function PhysicsUtils.momentOfInertia(part, axis, origin)
|
|
93
|
+
function PhysicsUtils.momentOfInertia(part: BasePart, axis: Vector3, origin: Vector3): number
|
|
93
94
|
local size = part.Size
|
|
94
95
|
local position = part.Position
|
|
95
96
|
local cframe = part.CFrame
|
|
96
97
|
local mass = part:GetMass()
|
|
97
98
|
|
|
98
|
-
local radius
|
|
99
|
+
local radius = (position - origin):Cross(axis)
|
|
99
100
|
local r2 = radius:Dot(radius)
|
|
100
101
|
local ip = mass * r2 -- inertia based on position
|
|
101
|
-
local s2 = size*size
|
|
102
|
-
local sa = cframe:
|
|
103
|
-
local id = (Vector3.new(s2.
|
|
104
|
-
return ip+id
|
|
102
|
+
local s2 = size * size
|
|
103
|
+
local sa = cframe:VectorToObjectSpace(axis)
|
|
104
|
+
local id = (Vector3.new(s2.Y + s2.Z, s2.Z + s2.X, s2.X + s2.Y)):Dot(sa * sa) * mass / 12 -- Inertia based on direction
|
|
105
|
+
return ip + id
|
|
105
106
|
end
|
|
106
107
|
|
|
107
108
|
--[=[
|
|
@@ -111,10 +112,10 @@ end
|
|
|
111
112
|
@param origin The origin of the axis (should be center of mass of the parts)
|
|
112
113
|
@return number
|
|
113
114
|
]=]
|
|
114
|
-
function PhysicsUtils.bodyMomentOfInertia(parts, axis, origin)
|
|
115
|
+
function PhysicsUtils.bodyMomentOfInertia(parts: { BasePart }, axis: Vector3, origin: Vector3): number
|
|
115
116
|
local totalBodyInertia = 0
|
|
116
117
|
|
|
117
|
-
for _, part in
|
|
118
|
+
for _, part in parts do
|
|
118
119
|
totalBodyInertia = totalBodyInertia + PhysicsUtils.momentOfInertia(part, axis, origin)
|
|
119
120
|
end
|
|
120
121
|
|
|
@@ -138,7 +139,7 @@ end
|
|
|
138
139
|
@param force Vector3 -- the force vector to apply
|
|
139
140
|
@param forcePosition Vector3 -- The position that the force is to be applied from (World vector).
|
|
140
141
|
]=]
|
|
141
|
-
function PhysicsUtils.applyForce(part, force, forcePosition)
|
|
142
|
+
function PhysicsUtils.applyForce(part: BasePart, force: Vector3, forcePosition: Vector3)
|
|
142
143
|
local parts = PhysicsUtils.getConnectedParts(part)
|
|
143
144
|
|
|
144
145
|
forcePosition = forcePosition or part.Position
|
|
@@ -150,15 +151,15 @@ function PhysicsUtils.applyForce(part, force, forcePosition)
|
|
|
150
151
|
local momentOfInertia = PhysicsUtils.bodyMomentOfInertia(parts, torque, centerOfMass)
|
|
151
152
|
local rotAcceleration
|
|
152
153
|
if momentOfInertia ~= 0 then
|
|
153
|
-
rotAcceleration = torque/momentOfInertia
|
|
154
|
+
rotAcceleration = torque / momentOfInertia
|
|
154
155
|
else
|
|
155
156
|
rotAcceleration = Vector3.zero -- We cannot divide by 0
|
|
156
157
|
end
|
|
157
158
|
|
|
158
|
-
local acceleration = force/mass
|
|
159
|
+
local acceleration = force / mass
|
|
159
160
|
|
|
160
|
-
part.
|
|
161
|
-
part.
|
|
161
|
+
part.AssemblyAngularVelocity = part.AssemblyAngularVelocity + rotAcceleration
|
|
162
|
+
part.AssemblyLinearVelocity = part.AssemblyLinearVelocity + acceleration
|
|
162
163
|
end
|
|
163
164
|
|
|
164
165
|
--[=[
|
|
@@ -169,7 +170,7 @@ end
|
|
|
169
170
|
@param emittingPart BasePart
|
|
170
171
|
@param acceleration Vector3
|
|
171
172
|
]=]
|
|
172
|
-
function PhysicsUtils.acceleratePart(part, emittingPart, acceleration)
|
|
173
|
+
function PhysicsUtils.acceleratePart(part: BasePart, emittingPart: BasePart, acceleration: Vector3)
|
|
173
174
|
local force = acceleration * part:GetMass()
|
|
174
175
|
local position = part.Position
|
|
175
176
|
|
|
@@ -177,4 +178,4 @@ function PhysicsUtils.acceleratePart(part, emittingPart, acceleration)
|
|
|
177
178
|
PhysicsUtils.applyForce(emittingPart, -force, position)
|
|
178
179
|
end
|
|
179
180
|
|
|
180
|
-
return PhysicsUtils
|
|
181
|
+
return PhysicsUtils
|