@quenty/trajectory 2.7.0 → 2.7.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 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
+ ## [2.7.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/trajectory@2.7.0...@quenty/trajectory@2.7.1) (2025-03-21)
7
+
8
+ **Note:** Version bump only for package @quenty/trajectory
9
+
10
+
11
+
12
+
13
+
6
14
  # [2.7.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/trajectory@2.6.1...@quenty/trajectory@2.7.0) (2025-02-18)
7
15
 
8
16
  **Note:** Version bump only for package @quenty/trajectory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/trajectory",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Utility function for estimating low and high arcs of projectiles. Solves for bullet drop given",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -29,8 +29,8 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@quenty/draw": "^7.8.0",
32
+ "@quenty/draw": "^7.8.1",
33
33
  "@quenty/loader": "^10.8.0"
34
34
  },
35
- "gitHead": "184a407d8d7366c39009444c3c9a7023cb176471"
35
+ "gitHead": "6b7c3e15e60cdb185986207b574e2b5591261e7a"
36
36
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Class of functions that can be used to minimize entrance velocity of a projectile.
3
4
  @class MinEntranceVelocityUtils
@@ -13,19 +14,19 @@ local SQRT_2 = math.sqrt(2)
13
14
  @param origin Vector3
14
15
  @param target Vector3
15
16
  @param accel Vector3
16
- @return number
17
+ @return Vector3
17
18
  ]=]
18
- function MinEntranceVelocityUtils.minimizeEntranceVelocity(origin, target, accel)
19
+ function MinEntranceVelocityUtils.minimizeEntranceVelocity(origin: Vector3, target: Vector3, accel: Vector3): Vector3
19
20
  local offset = target - origin
20
- local accelDist = accel.magnitude
21
- local offsetDist = offset.magnitude
21
+ local accelDist = accel.Magnitude
22
+ local offsetDist = offset.Magnitude
22
23
 
23
24
  local lowerTerm = math.sqrt(2 * accelDist * offsetDist)
24
25
  if lowerTerm == 0 then
25
26
  return Vector3.zero
26
27
  end
27
28
 
28
- return (accelDist*offset - accel*offsetDist) / lowerTerm
29
+ return (accelDist * offset - accel * offsetDist) / lowerTerm
29
30
  end
30
31
 
31
32
  --[=[
@@ -41,9 +42,14 @@ end
41
42
  @param accel Vector3
42
43
  @return Vector3
43
44
  ]=]
44
- function MinEntranceVelocityUtils.computeEntranceVelocity(velocity, origin, target, accel)
45
+ function MinEntranceVelocityUtils.computeEntranceVelocity(
46
+ velocity: Vector3,
47
+ origin: Vector3,
48
+ target: Vector3,
49
+ accel: Vector3
50
+ ): Vector3
45
51
  local entranceTime = MinEntranceVelocityUtils.computeEntranceTime(velocity, origin, target, accel)
46
- return accel*entranceTime + velocity
52
+ return accel * entranceTime + velocity
47
53
  end
48
54
 
49
55
  --[=[
@@ -59,7 +65,12 @@ end
59
65
  @param accel Vector3
60
66
  @return number
61
67
  ]=]
62
- function MinEntranceVelocityUtils.computeEntranceTime(velocity, origin, target, accel)
68
+ function MinEntranceVelocityUtils.computeEntranceTime(
69
+ velocity: Vector3,
70
+ origin: Vector3,
71
+ target: Vector3,
72
+ accel: Vector3
73
+ ): number
63
74
  local offset = target - origin
64
75
  local aa = accel:Dot(accel)
65
76
  local av = accel:Dot(velocity)
@@ -67,12 +78,12 @@ function MinEntranceVelocityUtils.computeEntranceTime(velocity, origin, target,
67
78
  local vo = velocity:Dot(offset)
68
79
  local oo = offset:Dot(offset)
69
80
 
70
- local lowerTerm = aa*vv - av*av
81
+ local lowerTerm = aa * vv - av * av
71
82
  if lowerTerm == 0 then
72
83
  return 0 -- We're already there
73
84
  end
74
85
 
75
- return SQRT_2*((vv*oo - vo*vo)/lowerTerm)^0.25
86
+ return SQRT_2 * ((vv * oo - vo * vo) / lowerTerm) ^ 0.25
76
87
  end
77
88
 
78
- return MinEntranceVelocityUtils
89
+ return MinEntranceVelocityUtils
@@ -12,22 +12,25 @@ local FINISH_COLOR = Color3.new(1, 0, 0)
12
12
 
13
13
  local TrajectoryDrawUtils = {}
14
14
 
15
- function TrajectoryDrawUtils.draw(velocity, origin, target, accel)
15
+ --[=[
16
+ Draws a trajectory out for debugging purposes
17
+ ]=]
18
+ function TrajectoryDrawUtils.draw(velocity: Vector3, origin: Vector3, target: Vector3, accel: Vector3)
16
19
  Draw.point(origin, ORIGIN_COLOR)
17
20
  Draw.point(target, FINISH_COLOR)
18
21
 
19
22
  local entranceTime = MinEntranceVelocityUtils.computeEntranceTime(velocity, origin, target, accel)
20
23
 
21
- for t=0, entranceTime, 0.1 do
24
+ for t = 0, entranceTime, 0.1 do
22
25
  local t0 = math.clamp(t, 0, entranceTime)
23
26
  local t1 = math.clamp(t + 0.1, 0, entranceTime)
24
27
 
25
- local p0 = origin + velocity*t0 + 0.5*accel*t0*t0
26
- local p1 = origin + velocity*t1 + 0.5*accel*t1*t1
28
+ local p0 = origin + velocity * t0 + 0.5 * accel * t0 * t0
29
+ local p1 = origin + velocity * t1 + 0.5 * accel * t1 * t1
27
30
 
28
- local percent = t/entranceTime
31
+ local percent = t / entranceTime
29
32
  Draw.line(p0, p1, ORIGIN_COLOR:Lerp(FINISH_COLOR, percent))
30
33
  end
31
34
  end
32
35
 
33
- return TrajectoryDrawUtils
36
+ return TrajectoryDrawUtils
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  Utility function for estimating low and high arcs of projectiles. Solves for bullet
3
4
  drop given
@@ -17,37 +18,44 @@
17
18
  @return Vector3? -- highTrajectory Initial velocity for a high trajectory arc
18
19
  @return Vector3? -- fallbackTrajectory Trajectory directly at target as afallback
19
20
  ]=]
20
- return function(origin, target, initialVelocity, gravityForce)
21
+ local function trajectory(
22
+ origin: Vector3,
23
+ target: Vector3,
24
+ initialVelocity: number,
25
+ gravityForce: number
26
+ ): (Vector3?, Vector3?, Vector3?)
21
27
  local g = -gravityForce
22
- local ox,oy,oz=origin.x,origin.y,origin.z
23
- local rx,rz=target.x-ox,target.z-oz
24
- local tx2=rx*rx+rz*rz
25
- local ty=target.y-oy
26
- if tx2>0 then
27
- local v2=initialVelocity*initialVelocity
28
-
29
- local c0=tx2/(2*(tx2+ty*ty))
30
- local c1=g*ty+v2
31
- local c22=v2*(2*g*ty+v2)-g*g*tx2
32
- if c22>0 then
33
- local c2=c22^0.5
34
- local t0x2=c0*(c1+c2)
35
- local t1x2=c0*(c1-c2)
36
-
37
- local tx,t0x,t1x=tx2^0.5,t0x2^0.5,t1x2^0.5
38
-
39
- local v0x,v0y,v0z=rx/tx*t0x,(v2-t0x2)^0.5,rz/tx*t0x
40
- local v1x,v1y,v1z=rx/tx*t1x,(v2-t1x2)^0.5,rz/tx*t1x
41
-
42
- local v0=Vector3.new(v0x,ty>g*tx2/(2*v2) and v0y or -v0y,v0z)
43
- local v1=Vector3.new(v1x,v1y,v1z)
44
-
45
- return v0,v1
28
+ local ox, oy, oz = origin.X, origin.Y, origin.Z
29
+ local rx, rz = target.X - ox, target.Z - oz
30
+ local tx2 = rx * rx + rz * rz
31
+ local ty = target.Y - oy
32
+ if tx2 > 0 then
33
+ local v2 = initialVelocity * initialVelocity
34
+
35
+ local c0 = tx2 / (2 * (tx2 + ty * ty))
36
+ local c1 = g * ty + v2
37
+ local c22 = v2 * (2 * g * ty + v2) - g * g * tx2
38
+ if c22 > 0 then
39
+ local c2 = c22 ^ 0.5
40
+ local t0x2 = c0 * (c1 + c2)
41
+ local t1x2 = c0 * (c1 - c2)
42
+
43
+ local tx, t0x, t1x = tx2 ^ 0.5, t0x2 ^ 0.5, t1x2 ^ 0.5
44
+
45
+ local v0x, v0y, v0z = rx / tx * t0x, (v2 - t0x2) ^ 0.5, rz / tx * t0x
46
+ local v1x, v1y, v1z = rx / tx * t1x, (v2 - t1x2) ^ 0.5, rz / tx * t1x
47
+
48
+ local v0 = Vector3.new(v0x, ty > g * tx2 / (2 * v2) and v0y or -v0y, v0z)
49
+ local v1 = Vector3.new(v1x, v1y, v1z)
50
+
51
+ return v0, v1
46
52
  else
47
- return nil, nil, Vector3.new(rx, (tx2^0.5), rz).unit * initialVelocity
53
+ return nil, nil, Vector3.new(rx, (tx2 ^ 0.5), rz).Unit * initialVelocity
48
54
  end
49
55
  else
50
- local v=Vector3.new(0,initialVelocity*(ty>0 and 1 or ty<0 and -1 or 0),0)
51
- return v,v
56
+ local v = Vector3.new(0, initialVelocity * (ty > 0 and 1 or ty < 0 and -1 or 0), 0)
57
+ return v, v, nil
52
58
  end
53
- end
59
+ end
60
+
61
+ return trajectory