dacha 0.18.0-alpha.3 → 0.18.0-alpha.4

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.
Files changed (138) hide show
  1. package/build/contrib/components/collider/index.d.ts +6 -6
  2. package/build/contrib/components/collider/index.js +5 -2
  3. package/build/contrib/components/rigid-body/index.d.ts +53 -7
  4. package/build/contrib/components/rigid-body/index.js +63 -7
  5. package/build/contrib/systems/physics-system/api.d.ts +15 -15
  6. package/build/contrib/systems/physics-system/api.js +15 -15
  7. package/build/contrib/systems/physics-system/physics-system.js +1 -0
  8. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-box-cast-aabb.d.ts +2 -0
  9. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-box-cast-aabb.js +18 -0
  10. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-capsule-cast-aabb.d.ts +2 -0
  11. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-capsule-cast-aabb.js +21 -0
  12. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-circle-cast-aabb.d.ts +2 -0
  13. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-circle-cast-aabb.js +15 -0
  14. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/index.js +6 -0
  15. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-cast-geometry.d.ts +3 -0
  16. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-cast-geometry.js +24 -0
  17. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-geometry.js +1 -1
  18. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-cast-geometry.d.ts +3 -0
  19. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-cast-geometry.js +43 -0
  20. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-geometry.d.ts +2 -0
  21. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-geometry.js +36 -11
  22. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-cast-geometry.d.ts +3 -0
  23. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-cast-geometry.js +9 -0
  24. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.js +1 -1
  25. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.js +1 -1
  26. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.d.ts +6 -0
  27. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.js +6 -0
  28. package/build/contrib/systems/physics-system/subsystems/collision-detection/index.d.ts +7 -6
  29. package/build/contrib/systems/physics-system/subsystems/collision-detection/index.js +26 -11
  30. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.d.ts +2 -2
  31. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.js +1 -3
  32. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-capsule/check-box-and-capsule-intersection.d.ts +2 -2
  33. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-capsule/check-box-and-capsule-intersection.js +1 -3
  34. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-capsule/utils.js +10 -10
  35. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.d.ts +2 -2
  36. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.js +3 -6
  37. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.d.ts +2 -2
  38. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.js +2 -4
  39. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.js +8 -8
  40. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/capsule-capsule/check-capsules-intersection.d.ts +2 -2
  41. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/capsule-capsule/check-capsules-intersection.js +1 -3
  42. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-capsule/check-circle-and-capsule-intersection.d.ts +2 -2
  43. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-capsule/check-circle-and-capsule-intersection.js +3 -5
  44. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.d.ts +2 -2
  45. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.js +5 -5
  46. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.d.ts +2 -2
  47. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.js +3 -5
  48. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/capsule.js +2 -2
  49. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/cast.d.ts +3 -0
  50. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/cast.js +9 -0
  51. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/points.js +2 -3
  52. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/projections.js +2 -2
  53. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/segment-distance.js +6 -6
  54. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.d.ts +2 -2
  55. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.js +0 -10
  56. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.d.ts +2 -2
  57. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.js +4 -6
  58. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-capsule/check-point-and-capsule-intersection.d.ts +2 -2
  59. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-capsule/check-point-and-capsule-intersection.js +3 -5
  60. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.d.ts +2 -2
  61. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.js +3 -5
  62. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.d.ts +2 -2
  63. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.js +3 -5
  64. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/segment-capsule/check-segment-and-capsule-intersection.d.ts +2 -2
  65. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/segment-capsule/check-segment-and-capsule-intersection.js +1 -3
  66. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.d.ts +3 -2
  67. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.js +38 -28
  68. package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.d.ts +11 -6
  69. package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.js +74 -14
  70. package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/index.d.ts +2 -0
  71. package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/index.js +12 -0
  72. package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-box/check-ray-and-box-intersection.d.ts +3 -2
  73. package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-box/check-ray-and-box-intersection.js +8 -12
  74. package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/ray-capsule/check-ray-and-capsule-intersection.d.ts +20 -0
  75. package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-capsule/check-ray-and-capsule-intersection.js +27 -39
  76. package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-circle/check-ray-and-circle-intersection.d.ts +3 -2
  77. package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-circle/check-ray-and-circle-intersection.js +8 -10
  78. package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/check-ray-and-segment-intersection.d.ts +3 -2
  79. package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/check-ray-and-segment-intersection.js +9 -13
  80. package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/types.d.ts +4 -0
  81. package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/types.js +1 -0
  82. package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/check-collider.js +1 -4
  83. package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/get-orientation-data.js +1 -4
  84. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-box/check-box-cast-and-box.d.ts +3 -0
  85. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-box/check-box-cast-and-box.js +12 -0
  86. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-capsule/check-box-cast-and-capsule.d.ts +3 -0
  87. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-capsule/check-box-cast-and-capsule.js +12 -0
  88. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-circle/check-box-cast-and-circle.d.ts +3 -0
  89. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-circle/check-box-cast-and-circle.js +12 -0
  90. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-segment/check-box-cast-and-segment.d.ts +3 -0
  91. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-segment/check-box-cast-and-segment.js +15 -0
  92. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-utils.d.ts +7 -0
  93. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-utils.js +146 -0
  94. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-box/check-capsule-cast-and-box.d.ts +3 -0
  95. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-box/check-capsule-cast-and-box.js +22 -0
  96. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-capsule/check-capsule-cast-and-capsule.d.ts +3 -0
  97. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-capsule/check-capsule-cast-and-capsule.js +21 -0
  98. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-circle/check-capsule-cast-and-circle.d.ts +3 -0
  99. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-circle/check-capsule-cast-and-circle.js +20 -0
  100. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-segment/check-capsule-cast-and-segment.d.ts +3 -0
  101. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-segment/check-capsule-cast-and-segment.js +21 -0
  102. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-utils.d.ts +3 -0
  103. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-utils.js +16 -0
  104. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-box/check-circle-cast-and-box.d.ts +3 -0
  105. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-box/check-circle-cast-and-box.js +22 -0
  106. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-capsule/check-circle-cast-and-capsule.d.ts +3 -0
  107. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-capsule/check-circle-cast-and-capsule.js +18 -0
  108. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-circle/check-circle-cast-and-circle.d.ts +3 -0
  109. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-circle/check-circle-cast-and-circle.js +22 -0
  110. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-segment/check-circle-cast-and-segment.d.ts +3 -0
  111. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-segment/check-circle-cast-and-segment.js +18 -0
  112. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/index.d.ts +2 -0
  113. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/index.js +32 -0
  114. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/tests/helpers.d.ts +6 -0
  115. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/tests/helpers.js +39 -0
  116. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/types.d.ts +4 -0
  117. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/types.js +1 -0
  118. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/utils.d.ts +4 -0
  119. package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/utils.js +11 -0
  120. package/build/contrib/systems/physics-system/subsystems/collision-detection/types.d.ts +12 -1
  121. package/build/contrib/systems/physics-system/subsystems/collision-detection/utils.d.ts +5 -0
  122. package/build/contrib/systems/physics-system/subsystems/collision-detection/utils.js +6 -0
  123. package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.d.ts +6 -0
  124. package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.js +65 -4
  125. package/build/contrib/systems/physics-system/subsystems/physics/index.d.ts +2 -0
  126. package/build/contrib/systems/physics-system/subsystems/physics/index.js +43 -5
  127. package/build/contrib/systems/physics-system/tests/helpers.d.ts +20 -0
  128. package/build/contrib/systems/physics-system/tests/helpers.js +129 -0
  129. package/build/contrib/systems/physics-system/types.d.ts +53 -6
  130. package/build/engine/math-lib/vector/ops.d.ts +9 -1
  131. package/build/engine/math-lib/vector/ops.js +15 -0
  132. package/build/engine/template/template-collection.js +3 -0
  133. package/package.json +1 -1
  134. package/build/contrib/systems/physics-system/consts.d.ts +0 -4
  135. package/build/contrib/systems/physics-system/consts.js +0 -4
  136. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-capsule/check-ray-and-capsule-intersection.d.ts +0 -11
  137. /package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/utils.d.ts +0 -0
  138. /package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/utils.js +0 -0
@@ -7,6 +7,7 @@ export interface BaseColliderConfig {
7
7
  offsetY: number;
8
8
  layer: string;
9
9
  debugColor?: string;
10
+ disabled: boolean;
10
11
  }
11
12
  export interface BoxColliderConfig extends BaseColliderConfig {
12
13
  type: 'box';
@@ -26,10 +27,7 @@ export interface SegmentColliderConfig extends BaseColliderConfig {
26
27
  }
27
28
  export interface CapsuleColliderConfig extends BaseColliderConfig {
28
29
  type: 'capsule';
29
- point1X: number;
30
- point1Y: number;
31
- point2X: number;
32
- point2Y: number;
30
+ height: number;
33
31
  radius: number;
34
32
  }
35
33
  export type ColliderConfig = BoxColliderConfig | CircleColliderConfig | SegmentColliderConfig | CapsuleColliderConfig;
@@ -48,8 +46,7 @@ export interface SegmentColliderShape {
48
46
  }
49
47
  export interface CapsuleColliderShape {
50
48
  type: 'capsule';
51
- point1: Point;
52
- point2: Point;
49
+ height: number;
53
50
  radius: number;
54
51
  }
55
52
  export type ColliderShape = BoxColliderShape | CircleColliderShape | SegmentColliderShape | CapsuleColliderShape;
@@ -69,6 +66,7 @@ export type ColliderShape = BoxColliderShape | CircleColliderShape | SegmentColl
69
66
  * sizeX: 64,
70
67
  * sizeY: 64,
71
68
  * layer: 'default',
69
+ * disabled: false,
72
70
  * });
73
71
  *
74
72
  * // Create a circle collider
@@ -78,6 +76,7 @@ export type ColliderShape = BoxColliderShape | CircleColliderShape | SegmentColl
78
76
  * offsetY: 0,
79
77
  * radius: 32,
80
78
  * layer: 'default',
79
+ * disabled: false,
81
80
  * });
82
81
  *
83
82
  * // Add to actor
@@ -90,6 +89,7 @@ export declare class Collider extends Component {
90
89
  offset: Point;
91
90
  layer: string;
92
91
  debugColor?: string;
92
+ disabled: boolean;
93
93
  shape: ColliderShape;
94
94
  constructor(config: ColliderConfig);
95
95
  }
@@ -15,6 +15,7 @@ import { Component } from '../../../engine/component';
15
15
  * sizeX: 64,
16
16
  * sizeY: 64,
17
17
  * layer: 'default',
18
+ * disabled: false,
18
19
  * });
19
20
  *
20
21
  * // Create a circle collider
@@ -24,6 +25,7 @@ import { Component } from '../../../engine/component';
24
25
  * offsetY: 0,
25
26
  * radius: 32,
26
27
  * layer: 'default',
28
+ * disabled: false,
27
29
  * });
28
30
  *
29
31
  * // Add to actor
@@ -36,12 +38,14 @@ export class Collider extends Component {
36
38
  offset;
37
39
  layer;
38
40
  debugColor;
41
+ disabled;
39
42
  shape;
40
43
  constructor(config) {
41
44
  super();
42
45
  this.offset = { x: config.offsetX, y: config.offsetY };
43
46
  this.layer = config.layer;
44
47
  this.debugColor = config.debugColor;
48
+ this.disabled = config.disabled;
45
49
  switch (config.type) {
46
50
  case 'box':
47
51
  this.shape = {
@@ -65,8 +69,7 @@ export class Collider extends Component {
65
69
  case 'capsule':
66
70
  this.shape = {
67
71
  type: config.type,
68
- point1: { x: config.point1X, y: config.point1Y },
69
- point2: { x: config.point2X, y: config.point2Y },
72
+ height: config.height,
70
73
  radius: config.radius,
71
74
  };
72
75
  }
@@ -1,12 +1,15 @@
1
1
  import { Component } from '../../../engine/component';
2
2
  import { Vector2 } from '../../../engine/math-lib';
3
- export type RigidBodyType = 'dynamic' | 'static';
3
+ export type RigidBodyType = 'dynamic' | 'static' | 'kinematic';
4
4
  export interface RigidBodyConfig {
5
5
  type: RigidBodyType;
6
- mass: number;
7
- gravityScale: number;
8
- linearDamping: number;
6
+ mass?: number;
7
+ gravityScale?: number;
8
+ linearDamping?: number;
9
9
  disabled: boolean;
10
+ oneWay: boolean;
11
+ oneWayNormalX?: number;
12
+ oneWayNormalY?: number;
10
13
  }
11
14
  /**
12
15
  * RigidBody component for defining rigid body physics.
@@ -37,9 +40,10 @@ export interface RigidBodyConfig {
37
40
  export declare class RigidBody extends Component {
38
41
  private _mass;
39
42
  private _inverseMass;
40
- /** Type of the rigid body */
41
- type: RigidBodyType;
42
- /** Mass of the rigid body */
43
+ /** @internal Pending one-step kinematic movement target */
44
+ _movementTarget: Vector2 | null;
45
+ /** Body type that defines how the rigid body participates in simulation */
46
+ readonly type: RigidBodyType;
43
47
  /** Gravity scale of the rigid body */
44
48
  gravityScale: number;
45
49
  /** Linear damping value used to slow down movement over time */
@@ -50,19 +54,61 @@ export declare class RigidBody extends Component {
50
54
  disabled: boolean;
51
55
  /** Whether rigid body is sleeping */
52
56
  sleeping: boolean;
57
+ /** Force applied to the rigid body */
53
58
  force: Vector2;
59
+ /** Impulse applied to the rigid body */
54
60
  impulse: Vector2;
61
+ /** Whether contacts should only be resolved from one side */
62
+ oneWay: boolean;
63
+ /** Local-space normal that points toward the blocking side */
64
+ oneWayNormal?: Vector2;
55
65
  /**
56
66
  * Creates a new RigidBody component.
57
67
  * @param config - Configuration for the rigid body
58
68
  */
59
69
  constructor(config: RigidBodyConfig);
60
70
  get mass(): number;
71
+ /**
72
+ * Sets the mass used by dynamic bodies.
73
+ *
74
+ * Non-positive values make the body immovable by forces and impulses.
75
+ */
61
76
  set mass(value: number);
77
+ /**
78
+ * Returns the inverse mass.
79
+ *
80
+ * Bodies with zero or negative mass return `0`.
81
+ */
62
82
  get inverseMass(): number;
83
+ /**
84
+ * Adds a continuous force to a dynamic body for the next physics step.
85
+ *
86
+ * Affects only active dynamic bodies.
87
+ */
63
88
  applyForce(force: Vector2): void;
89
+ /**
90
+ * Adds an instantaneous impulse to a dynamic body for the next physics step.
91
+ *
92
+ * Affects only active dynamic bodies.
93
+ */
64
94
  applyImpulse(impulse: Vector2): void;
95
+ /**
96
+ * Marks the rigid body as awake so it can be simulated.
97
+ */
65
98
  wakeUp(): void;
99
+ /**
100
+ * Marks the rigid body as sleeping so dynamic integration can skip it.
101
+ */
66
102
  sleep(): void;
103
+ /**
104
+ * Clears all accumulated force and impulse values.
105
+ */
67
106
  clearForces(): void;
107
+ /**
108
+ * Moves a kinematic body to a target position on the next physics step.
109
+ *
110
+ * The physics system computes a one-step velocity from the current position
111
+ * to this target so contacts can react to the kinematic movement.
112
+ */
113
+ movePosition(position: Vector2): void;
68
114
  }
@@ -29,9 +29,10 @@ import { Vector2 } from '../../../engine/math-lib';
29
29
  export class RigidBody extends Component {
30
30
  _mass;
31
31
  _inverseMass;
32
- /** Type of the rigid body */
32
+ /** @internal Pending one-step kinematic movement target */
33
+ _movementTarget;
34
+ /** Body type that defines how the rigid body participates in simulation */
33
35
  type;
34
- /** Mass of the rigid body */
35
36
  /** Gravity scale of the rigid body */
36
37
  gravityScale;
37
38
  /** Linear damping value used to slow down movement over time */
@@ -42,8 +43,14 @@ export class RigidBody extends Component {
42
43
  disabled;
43
44
  /** Whether rigid body is sleeping */
44
45
  sleeping;
46
+ /** Force applied to the rigid body */
45
47
  force;
48
+ /** Impulse applied to the rigid body */
46
49
  impulse;
50
+ /** Whether contacts should only be resolved from one side */
51
+ oneWay;
52
+ /** Local-space normal that points toward the blocking side */
53
+ oneWayNormal;
47
54
  /**
48
55
  * Creates a new RigidBody component.
49
56
  * @param config - Configuration for the rigid body
@@ -52,49 +59,98 @@ export class RigidBody extends Component {
52
59
  super();
53
60
  this._mass = 0;
54
61
  this._inverseMass = 0;
62
+ this._movementTarget = null;
55
63
  this.type = config.type;
56
- this.mass = config.mass;
57
- this.gravityScale = config.gravityScale;
58
- this.linearDamping = config.linearDamping;
64
+ this.mass = config.mass ?? 0;
65
+ this.gravityScale = config.gravityScale ?? 0;
66
+ this.linearDamping = config.linearDamping ?? 0;
59
67
  this.linearVelocity = new Vector2(0, 0);
60
68
  this.disabled = config.disabled;
61
69
  this.sleeping = false;
62
70
  this.force = new Vector2(0, 0);
63
71
  this.impulse = new Vector2(0, 0);
72
+ this.oneWay = config.oneWay ?? false;
73
+ if (this.oneWay) {
74
+ this.oneWayNormal = new Vector2(config.oneWayNormalX ?? 0, config.oneWayNormalY ?? 0).normalize();
75
+ if (this.oneWayNormal.magnitude === 0) {
76
+ throw new Error('One-way rigid body normal must be non-zero');
77
+ }
78
+ }
64
79
  }
65
80
  get mass() {
66
81
  return this._mass;
67
82
  }
83
+ /**
84
+ * Sets the mass used by dynamic bodies.
85
+ *
86
+ * Non-positive values make the body immovable by forces and impulses.
87
+ */
68
88
  set mass(value) {
69
89
  this._mass = value;
70
90
  this._inverseMass = value > 0 ? 1 / value : 0;
71
91
  }
92
+ /**
93
+ * Returns the inverse mass.
94
+ *
95
+ * Bodies with zero or negative mass return `0`.
96
+ */
72
97
  get inverseMass() {
73
98
  return this._inverseMass;
74
99
  }
100
+ /**
101
+ * Adds a continuous force to a dynamic body for the next physics step.
102
+ *
103
+ * Affects only active dynamic bodies.
104
+ */
75
105
  applyForce(force) {
76
- if (this.disabled || this.type === 'static') {
106
+ if (this.disabled || this.type !== 'dynamic') {
77
107
  return;
78
108
  }
79
109
  this.wakeUp();
80
110
  this.force.add(force);
81
111
  }
112
+ /**
113
+ * Adds an instantaneous impulse to a dynamic body for the next physics step.
114
+ *
115
+ * Affects only active dynamic bodies.
116
+ */
82
117
  applyImpulse(impulse) {
83
- if (this.disabled || this.type === 'static') {
118
+ if (this.disabled || this.type !== 'dynamic') {
84
119
  return;
85
120
  }
86
121
  this.wakeUp();
87
122
  this.impulse.add(impulse);
88
123
  }
124
+ /**
125
+ * Marks the rigid body as awake so it can be simulated.
126
+ */
89
127
  wakeUp() {
90
128
  this.sleeping = false;
91
129
  }
130
+ /**
131
+ * Marks the rigid body as sleeping so dynamic integration can skip it.
132
+ */
92
133
  sleep() {
93
134
  this.sleeping = true;
94
135
  }
136
+ /**
137
+ * Clears all accumulated force and impulse values.
138
+ */
95
139
  clearForces() {
96
140
  this.force.multiplyNumber(0);
97
141
  this.impulse.multiplyNumber(0);
98
142
  }
143
+ /**
144
+ * Moves a kinematic body to a target position on the next physics step.
145
+ *
146
+ * The physics system computes a one-step velocity from the current position
147
+ * to this target so contacts can react to the kinematic movement.
148
+ */
149
+ movePosition(position) {
150
+ if (this.disabled || this.type !== 'kinematic') {
151
+ return;
152
+ }
153
+ this._movementTarget = position.clone();
154
+ }
99
155
  }
100
156
  RigidBody.componentName = 'RigidBody';
@@ -1,6 +1,6 @@
1
1
  import type { Actor } from '../../../engine/actor';
2
2
  import type { CollisionDetectionSubsystem } from './subsystems';
3
- import type { RaycastHit, RaycastParams, OverlapBoxParams, OverlapCircleParams, OverlapPointParams } from './types';
3
+ import type { CastHit, RaycastParams, OverlapParams, ShapeCastParams } from './types';
4
4
  /**
5
5
  * API that provides methods for performing physics queries such as raycasting and overlap tests.
6
6
  *
@@ -23,7 +23,7 @@ export declare class PhysicsAPI {
23
23
  * @param params - Raycast parameters
24
24
  * @returns The nearest hit or `null` when nothing is hit
25
25
  */
26
- raycast(params: RaycastParams): RaycastHit | null;
26
+ raycast(params: RaycastParams): CastHit | null;
27
27
  /**
28
28
  * Casts a ray and returns all hits sorted by distance.
29
29
  *
@@ -33,26 +33,26 @@ export declare class PhysicsAPI {
33
33
  * @param params - Raycast parameters
34
34
  * @returns All hits sorted from nearest to farthest
35
35
  */
36
- raycastAll(params: RaycastParams): RaycastHit[];
36
+ raycastAll(params: RaycastParams): CastHit[];
37
37
  /**
38
- * Returns all actors whose colliders contain the given point.
38
+ * Returns all actors whose colliders overlap the given query shape.
39
39
  *
40
- * @param params - Point overlap parameters
41
- * @returns Actors whose colliders overlap the point
40
+ * @param params - Overlap parameters
41
+ * @returns Actors whose colliders overlap the shape
42
42
  */
43
- overlapPoint(params: OverlapPointParams): Actor[];
43
+ overlapShape(params: OverlapParams): Actor[];
44
44
  /**
45
- * Returns all actors whose colliders overlap the given circle.
45
+ * Casts a shape and returns the nearest hit, if any.
46
46
  *
47
- * @param params - Circle overlap parameters
48
- * @returns Actors whose colliders overlap the circle
47
+ * @param params - Shape cast parameters
48
+ * @returns The nearest hit or `null` when nothing is hit
49
49
  */
50
- overlapCircle(params: OverlapCircleParams): Actor[];
50
+ shapeCast(params: ShapeCastParams): CastHit | null;
51
51
  /**
52
- * Returns all actors whose colliders overlap the given box.
52
+ * Casts a shape and returns all hits sorted by distance.
53
53
  *
54
- * @param params - Box overlap parameters
55
- * @returns Actors whose colliders overlap the box
54
+ * @param params - Shape cast parameters
55
+ * @returns All hits sorted from nearest to farthest
56
56
  */
57
- overlapBox(params: OverlapBoxParams): Actor[];
57
+ shapeCastAll(params: ShapeCastParams): CastHit[];
58
58
  }
@@ -38,30 +38,30 @@ export class PhysicsAPI {
38
38
  return this.collisionDetectionSubsystem.raycastAll(params);
39
39
  }
40
40
  /**
41
- * Returns all actors whose colliders contain the given point.
41
+ * Returns all actors whose colliders overlap the given query shape.
42
42
  *
43
- * @param params - Point overlap parameters
44
- * @returns Actors whose colliders overlap the point
43
+ * @param params - Overlap parameters
44
+ * @returns Actors whose colliders overlap the shape
45
45
  */
46
- overlapPoint(params) {
47
- return this.collisionDetectionSubsystem.overlapPoint(params);
46
+ overlapShape(params) {
47
+ return this.collisionDetectionSubsystem.overlapShape(params);
48
48
  }
49
49
  /**
50
- * Returns all actors whose colliders overlap the given circle.
50
+ * Casts a shape and returns the nearest hit, if any.
51
51
  *
52
- * @param params - Circle overlap parameters
53
- * @returns Actors whose colliders overlap the circle
52
+ * @param params - Shape cast parameters
53
+ * @returns The nearest hit or `null` when nothing is hit
54
54
  */
55
- overlapCircle(params) {
56
- return this.collisionDetectionSubsystem.overlapCircle(params);
55
+ shapeCast(params) {
56
+ return this.collisionDetectionSubsystem.shapeCast(params);
57
57
  }
58
58
  /**
59
- * Returns all actors whose colliders overlap the given box.
59
+ * Casts a shape and returns all hits sorted by distance.
60
60
  *
61
- * @param params - Box overlap parameters
62
- * @returns Actors whose colliders overlap the box
61
+ * @param params - Shape cast parameters
62
+ * @returns All hits sorted from nearest to farthest
63
63
  */
64
- overlapBox(params) {
65
- return this.collisionDetectionSubsystem.overlapBox(params);
64
+ shapeCastAll(params) {
65
+ return this.collisionDetectionSubsystem.shapeCastAll(params);
66
66
  }
67
67
  }
@@ -42,6 +42,7 @@ export class PhysicsSystem extends SceneSystem {
42
42
  const contacts = this.collisionDetectionSubsystem.update();
43
43
  this.constraintSolver.update(contacts);
44
44
  this.collisionBroadcastSubsystem.update(contacts);
45
+ this.physicsSubsystem.lateUpdate();
45
46
  }
46
47
  }
47
48
  PhysicsSystem.systemName = 'PhysicsSystem';
@@ -0,0 +1,2 @@
1
+ import type { AABB, Geometry } from '../types';
2
+ export declare const buildBoxCastAABB: (params: Geometry) => AABB;
@@ -0,0 +1,18 @@
1
+ export const buildBoxCastAABB = (params) => {
2
+ const { points, direction, maxDistance } = params;
3
+ const endPoints = points.map((point) => ({
4
+ x: point.x + direction.x * maxDistance,
5
+ y: point.y + direction.y * maxDistance,
6
+ }));
7
+ const castPoints = [...points, ...endPoints];
8
+ return {
9
+ min: {
10
+ x: Math.min(...castPoints.map((point) => point.x)),
11
+ y: Math.min(...castPoints.map((point) => point.y)),
12
+ },
13
+ max: {
14
+ x: Math.max(...castPoints.map((point) => point.x)),
15
+ y: Math.max(...castPoints.map((point) => point.y)),
16
+ },
17
+ };
18
+ };
@@ -0,0 +1,2 @@
1
+ import type { AABB, Geometry } from '../types';
2
+ export declare const buildCapsuleCastAABB: (params: Geometry) => AABB;
@@ -0,0 +1,21 @@
1
+ export const buildCapsuleCastAABB = (params) => {
2
+ const { point1, point2, radius, direction, maxDistance } = params;
3
+ const endPoint1 = {
4
+ x: point1.x + direction.x * maxDistance,
5
+ y: point1.y + direction.y * maxDistance,
6
+ };
7
+ const endPoint2 = {
8
+ x: point2.x + direction.x * maxDistance,
9
+ y: point2.y + direction.y * maxDistance,
10
+ };
11
+ return {
12
+ min: {
13
+ x: Math.min(point1.x, point2.x, endPoint1.x, endPoint2.x) - radius,
14
+ y: Math.min(point1.y, point2.y, endPoint1.y, endPoint2.y) - radius,
15
+ },
16
+ max: {
17
+ x: Math.max(point1.x, point2.x, endPoint1.x, endPoint2.x) + radius,
18
+ y: Math.max(point1.y, point2.y, endPoint1.y, endPoint2.y) + radius,
19
+ },
20
+ };
21
+ };
@@ -0,0 +1,2 @@
1
+ import type { AABB, Geometry } from '../types';
2
+ export declare const buildCircleCastAABB: (params: Geometry) => AABB;
@@ -0,0 +1,15 @@
1
+ export const buildCircleCastAABB = (params) => {
2
+ const { center, radius, direction, maxDistance } = params;
3
+ const endX = center.x + direction.x * maxDistance;
4
+ const endY = center.y + direction.y * maxDistance;
5
+ return {
6
+ min: {
7
+ x: Math.min(center.x, endX) - radius,
8
+ y: Math.min(center.y, endY) - radius,
9
+ },
10
+ max: {
11
+ x: Math.max(center.x, endX) + radius,
12
+ y: Math.max(center.y, endY) + radius,
13
+ },
14
+ };
15
+ };
@@ -4,6 +4,9 @@ import { buildCircleAABB } from './build-circle-aabb';
4
4
  import { buildPointAABB } from './build-point-aabb';
5
5
  import { buildRayAABB } from './build-ray-aabb';
6
6
  import { buildSegmentAABB } from './build-segment-aabb';
7
+ import { buildCircleCastAABB } from './build-circle-cast-aabb';
8
+ import { buildCapsuleCastAABB } from './build-capsule-cast-aabb';
9
+ import { buildBoxCastAABB } from './build-box-cast-aabb';
7
10
  export const aabbBuilders = {
8
11
  box: buildBoxAABB,
9
12
  capsule: buildCapsuleAABB,
@@ -11,4 +14,7 @@ export const aabbBuilders = {
11
14
  segment: buildSegmentAABB,
12
15
  point: buildPointAABB,
13
16
  ray: buildRayAABB,
17
+ circleCast: buildCircleCastAABB,
18
+ capsuleCast: buildCapsuleCastAABB,
19
+ boxCast: buildBoxCastAABB,
14
20
  };
@@ -0,0 +1,3 @@
1
+ import type { BoxCastGeometry } from '../types';
2
+ import type { BoxCastParams } from '../../../types';
3
+ export declare function buildBoxCastGeometry(shapeCast: BoxCastParams): BoxCastGeometry;
@@ -0,0 +1,24 @@
1
+ import { buildBoxGeometry } from './build-box-geometry';
2
+ export function buildBoxCastGeometry(shapeCast) {
3
+ const box = buildBoxGeometry(shapeCast);
4
+ let minX = Infinity;
5
+ let maxX = -Infinity;
6
+ let minY = Infinity;
7
+ let maxY = -Infinity;
8
+ for (const point of box.points) {
9
+ minX = Math.min(minX, point.x);
10
+ maxX = Math.max(maxX, point.x);
11
+ minY = Math.min(minY, point.y);
12
+ maxY = Math.max(maxY, point.y);
13
+ }
14
+ return {
15
+ ...box,
16
+ origin: box.center,
17
+ direction: shapeCast.direction.normalize(),
18
+ maxDistance: shapeCast.maxDistance,
19
+ halfExtents: {
20
+ x: (maxX - minX) / 2,
21
+ y: (maxY - minY) / 2,
22
+ },
23
+ };
24
+ }
@@ -25,7 +25,7 @@ export function buildBoxGeometry(colliderOrOverlap, transform) {
25
25
  scaleY = transform.world.scale.y;
26
26
  }
27
27
  else {
28
- const overlap = colliderOrOverlap;
28
+ const overlap = colliderOrOverlap.shape;
29
29
  centerX = 0;
30
30
  centerY = 0;
31
31
  sizeX = overlap.size.x;
@@ -0,0 +1,3 @@
1
+ import type { CapsuleCastGeometry } from '../types';
2
+ import type { CapsuleCastParams } from '../../../types';
3
+ export declare function buildCapsuleCastGeometry(shapeCast: CapsuleCastParams): CapsuleCastGeometry;
@@ -0,0 +1,43 @@
1
+ import { isZero, isDefinitelyPositive } from '../utils';
2
+ import { buildCapsuleGeometry } from './build-capsule-geometry';
3
+ import { buildBoxCastGeometry } from './build-box-cast-geometry';
4
+ export function buildCapsuleCastGeometry(shapeCast) {
5
+ const capsule = buildCapsuleGeometry(shapeCast);
6
+ const boxSizeX = isZero(capsule.point2.x - capsule.point1.x)
7
+ ? capsule.radius * 2
8
+ : Math.abs(capsule.point2.x - capsule.point1.x);
9
+ const boxSizeY = isZero(capsule.point2.y - capsule.point1.y)
10
+ ? capsule.radius * 2
11
+ : Math.abs(capsule.point2.y - capsule.point1.y);
12
+ return {
13
+ ...capsule,
14
+ cap1: {
15
+ center: capsule.point1,
16
+ origin: capsule.point1,
17
+ radius: capsule.radius,
18
+ direction: shapeCast.direction,
19
+ maxDistance: shapeCast.maxDistance,
20
+ },
21
+ cap2: {
22
+ center: capsule.point2,
23
+ origin: capsule.point2,
24
+ radius: capsule.radius,
25
+ direction: shapeCast.direction,
26
+ maxDistance: shapeCast.maxDistance,
27
+ },
28
+ box: isDefinitelyPositive(boxSizeX) && isDefinitelyPositive(boxSizeY)
29
+ ? buildBoxCastGeometry({
30
+ shape: {
31
+ type: 'box',
32
+ center: capsule.center,
33
+ size: { x: boxSizeX, y: boxSizeY },
34
+ },
35
+ direction: shapeCast.direction,
36
+ maxDistance: shapeCast.maxDistance,
37
+ })
38
+ : null,
39
+ origin: capsule.center,
40
+ direction: shapeCast.direction.normalize(),
41
+ maxDistance: shapeCast.maxDistance,
42
+ };
43
+ }
@@ -1,3 +1,5 @@
1
1
  import type { Collider, Transform } from '../../../../../components';
2
2
  import type { CapsuleGeometry } from '../types';
3
+ import type { OverlapCapsuleParams } from '../../../types';
4
+ export declare function buildCapsuleGeometry(overlap: OverlapCapsuleParams): CapsuleGeometry;
3
5
  export declare function buildCapsuleGeometry(collider: Collider, transform: Transform): CapsuleGeometry;