@quenty/physicsutils 3.0.0 → 3.0.1-canary.38bdfe3.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.
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
+ ## [3.0.1-canary.38bdfe3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/physicsutils@3.0.0...@quenty/physicsutils@3.0.1-canary.38bdfe3.0) (2022-09-07)
7
+
8
+ **Note:** Version bump only for package @quenty/physicsutils
9
+
10
+
11
+
12
+
13
+
6
14
  # [3.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/physicsutils@2.1.0...@quenty/physicsutils@3.0.0) (2022-05-21)
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": "3.0.0",
3
+ "version": "3.0.1-canary.38bdfe3.0",
4
4
  "description": "General physics library for use on Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,5 +27,5 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "9f7eaea7543c33c89d2e32c38491b13f9271f4f7"
30
+ "gitHead": "38bdfe3721bddf1d272628b1104b1d8e0abaf24f"
31
31
  }
@@ -1,149 +0,0 @@
1
- --[=[
2
- Basic kinematics calculator that can be used like a spring.
3
- @class Kinematics
4
- ]=]
5
-
6
- local Kinematics = {}
7
- Kinematics.ClassName = "Kinematics"
8
-
9
- --[=[
10
- Constructs a new kinematics class.
11
-
12
- ```lua
13
- local kinematics = Kinematics.new(0)
14
- kinematics.Acceleration = -32
15
- kinematics.Velocity = 10
16
-
17
- print(kinematics.Position) --> 0
18
- task.wait(1)
19
- print(kinematics.Position) --> -10
20
- ```
21
-
22
- @param initial T -- The initial parameter is a number or Vector3 (anything with * number and addition/subtraction).
23
- @param clock? () -> number -- The clock function is optional, and is used to update the kinematics class
24
- @return Kinematics<T>
25
- ]=]
26
- function Kinematics.new(initial, clock)
27
- initial = initial or 0
28
-
29
- local self = setmetatable({}, Kinematics)
30
-
31
- rawset(self, "_clock", clock or os.clock)
32
- rawset(self, "_position0", initial)
33
- rawset(self, "_velocity0", 0*initial)
34
- rawset(self, "_acceleration", 0*initial)
35
- rawset(self, "_speed", 0)
36
- rawset(self, "_time0", self._clock())
37
-
38
- return self
39
- end
40
-
41
- --[=[
42
- Impulses the current kinematics object, applying velocity to it.
43
- @param velocity T
44
- ]=]
45
- function Kinematics:Impulse(velocity)
46
- self.Velocity = self.Velocity + velocity
47
- end
48
-
49
- --[=[
50
- Skips forward in the set amount of time dictated by `delta`
51
- @param delta number
52
- ]=]
53
- function Kinematics:TimeSkip(delta)
54
- assert(type(delta) == "number", "Bad delta")
55
-
56
- local now = self._clock()
57
- local position, velocity = self:_positionVelocity(now+delta)
58
- rawset(self, "_position0", position)
59
- rawset(self, "_velocity0", velocity)
60
- rawset(self, "_time0", now)
61
- end
62
-
63
- --[=[
64
- Sets data from some external source
65
- @param startTime number
66
- @param position0 T
67
- @param velocity0 T
68
- @param acceleration T
69
- ]=]
70
- function Kinematics:SetData(startTime, position0, velocity0, acceleration)
71
- rawset(self, "_time0", startTime)
72
- rawset(self, "_position0", position0)
73
- rawset(self, "_velocity0", velocity0)
74
- rawset(self, "_acceleration", acceleration)
75
- end
76
-
77
- function Kinematics:__index(index)
78
- local now = self._clock()
79
-
80
- if Kinematics[index] then
81
- return Kinematics[index]
82
- elseif index == "Position" then
83
- local position, _ = self:_positionVelocity(now)
84
- return position
85
- elseif index == "Velocity" then
86
- local _, velocity = self:_positionVelocity(now)
87
- return velocity
88
- elseif index == "Acceleration" then
89
- return rawget(self, "_acceleration")
90
- elseif index == "StartTime" then
91
- return rawget(self, "_time0")
92
- elseif index == "StartPosition" then
93
- return rawget(self, "_position0")
94
- elseif index == "StartVelocity" then
95
- return rawget(self, "_velocity0")
96
- elseif index == "Speed" then
97
- return rawget(self, "_speed")
98
- elseif index == "Age" then
99
- return self._clock() - rawget(self, "_time0")
100
- elseif index == "Clock" then
101
- return rawget(self, "_clock")
102
- else
103
- error(("%q is not a valid member of Kinematics"):format(tostring(index)), 2)
104
- end
105
- end
106
-
107
- function Kinematics:__newindex(index, value)
108
- local now = self._clock()
109
- if index == "Position" then
110
- local _, velocity = self:_positionVelocity(now)
111
- rawset(self, "_position0", value)
112
- rawset(self, "_velocity0", velocity)
113
- elseif index == "Velocity" then
114
- local position, _ = self:_positionVelocity(now)
115
- rawset(self, "_position0", position)
116
- rawset(self, "_velocity0", value)
117
- elseif index == "Acceleration" then
118
- local position, velocity = self:_positionVelocity(now)
119
- rawset(self, "_position0", position)
120
- rawset(self, "_velocity0", velocity)
121
- rawset(self, "_acceleration", value)
122
- elseif index == "Speed" then
123
- local position, velocity = self:_positionVelocity(now)
124
- rawset(self, "_position0", position)
125
- rawset(self, "_velocity0", velocity)
126
- rawset(self, "_speed", value)
127
- elseif index == "Clock" then
128
- local position, velocity = self:_positionVelocity(now)
129
- rawset(self, "_position0", position)
130
- rawset(self, "_velocity0", velocity)
131
- rawset(self, "_clock", value)
132
- rawset(self, "_time0", value())
133
- else
134
- error(("%q is not a valid member of Kinematics"):format(tostring(index)), 2)
135
- end
136
- rawset(self, "_time0", now)
137
- end
138
-
139
- function Kinematics:_positionVelocity(now)
140
- local s = rawget(self, "_speed")
141
- local dt = s*(now - rawget(self, "_time0"))
142
- local a0 = rawget(self, "_acceleration")
143
- local v0 = rawget(self, "_velocity0")
144
- local p0 = rawget(self, "_position0")
145
- return p0 + v0*dt + 0.5*dt*dt*a0,
146
- v0 + a0*dt
147
- end
148
-
149
- return Kinematics