samengine 1.7.1 β†’ 1.7.3

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
1
  // Function to get the Version
2
2
  export function version() {
3
- return "1.7.1";
3
+ return "1.7.3";
4
4
  }
@@ -67,23 +67,25 @@ export function circleBoxCollision(circleObj, boxObj) {
67
67
  }
68
68
  export function resolveCollision(a, b, normal) {
69
69
  const rv = subtract2d(b.body.velocity, a.body.velocity);
70
- const velAlongNormal = dot2d(rv, normal);
71
- if (velAlongNormal > 0)
72
- return;
73
- const restitution = Math.min(a.body.restitution, b.body.restitution);
70
+ let velAlongNormal = dot2d(rv, normal);
74
71
  const invMassA = a.body.isStatic ? 0 : 1 / a.body.mass;
75
72
  const invMassB = b.body.isStatic ? 0 : 1 / b.body.mass;
73
+ // πŸ‘‰ WICHTIG: wenn leicht rein β†’ trotzdem pushen
74
+ if (velAlongNormal > -0.01) {
75
+ velAlongNormal = -0.01;
76
+ }
77
+ const restitution = Math.min(a.body.restitution, b.body.restitution);
76
78
  const j = -(1 + restitution) * velAlongNormal /
77
79
  (invMassA + invMassB);
78
80
  const impulse = scale2d(normal, j);
79
81
  if (!a.body.isStatic)
80
82
  a.body.velocity = subtract2d(a.body.velocity, scale2d(impulse, invMassA));
81
83
  if (!b.body.isStatic)
82
- b.body.velocity = subtract2d(b.body.velocity, scale2d(impulse, invMassB));
84
+ b.body.velocity = add2d(b.body.velocity, scale2d(impulse, invMassB));
83
85
  }
84
86
  export function positionalCorrection(a, b, normal, penetration) {
85
- const percent = 0.8; // StΓ€rke
86
- const slop = 0.01;
87
+ const percent = 1.0; // vorher 0.8
88
+ const slop = 0.001; // vorher 0.01
87
89
  const invMassA = a.body.isStatic ? 0 : 1 / a.body.mass;
88
90
  const invMassB = b.body.isStatic ? 0 : 1 / b.body.mass;
89
91
  const correction = scale2d(scale2d(normal, Math.max(penetration - slop, 0) / (invMassA + invMassB)), percent);
@@ -0,0 +1,2 @@
1
+ export { RigidBody, PhysicsObject, } from "./physicsObject.js";
2
+ export { PhysicsWorld } from "./physicsEngine.js";
@@ -0,0 +1,2 @@
1
+ export { RigidBody, PhysicsObject, } from "./physicsObject.js";
2
+ export { PhysicsWorld } from "./physicsEngine.js";
@@ -1,4 +1,4 @@
1
- import { makeVector2d, scale2d, add2d } from "../types/vector2d.js";
1
+ import { makeVector2d, scale2d, add2d, subtract2d, dot2d } from "../types/vector2d.js";
2
2
  import { aabbCollision, circleBoxCollision, circleCollision, positionalCorrection, resolveCollision } from "./collision.js";
3
3
  // Exapmle for a Use Case
4
4
  // const world = new PhysicsWorld();
@@ -55,6 +55,19 @@ export class PhysicsWorld {
55
55
  }
56
56
  if (collision) {
57
57
  resolveCollision(a, b, collision.normal);
58
+ // πŸ‘‰ HIER REIN!
59
+ if (!a.body.isStatic && b.body.isStatic) {
60
+ const dot = dot2d(a.body.velocity, collision.normal);
61
+ if (dot < 0) {
62
+ a.body.velocity = subtract2d(a.body.velocity, scale2d(collision.normal, dot * 2));
63
+ }
64
+ }
65
+ if (!b.body.isStatic && a.body.isStatic) {
66
+ const dot = dot2d(b.body.velocity, scale2d(collision.normal, -1));
67
+ if (dot < 0) {
68
+ b.body.velocity = subtract2d(b.body.velocity, scale2d(scale2d(collision.normal, -1), dot * 2));
69
+ }
70
+ }
58
71
  positionalCorrection(a, b, collision.normal, collision.penetration);
59
72
  }
60
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samengine",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "A TypeScript game library to make HTML Games",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -16,7 +16,8 @@
16
16
  "./types": "./dist/types/index.js",
17
17
  "./sound": "./dist/sound/index.js",
18
18
  "./utils": "./dist/utils/index.js",
19
- "./build": "./dist/build/index.js"
19
+ "./build": "./dist/build/index.js",
20
+ "./physics": "./dist/physics/index.js"
20
21
  },
21
22
  "keywords": [
22
23
  "game",