diff --git a/README.md b/README.md index 9481bfdd..2b4c777f 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ const system = new System(); Bodies possess various properties: -- **Position**: `pos: Vector`, `x: number`, `y: number`. +- **Position**: Use `setPosition(x: number, y: number)` for teleport and `move(speed: number)` for moving forward in direction of its angle. - **Scale**: Use `setScale(x: number, y: number)` for setting and `scale: Vector` for getting scale - **Rotation**: Use `setAngle(radians: number)` for setting and `angle: number` for getting and `deg2rad(degrees: number)` to convert to radians. - **Offset**: Use `setOffset(offset: Vector)` for setting and `offset: Vector` for getting offset from the body center. @@ -79,12 +79,14 @@ Manipulate body attributes and update the collision system: ```ts // if omitted updateNow is true const updateNow = false; +// this should be time scaled, 1 for example +const speed = 1; // teleport box.setPosition(x, y, updateNow); box.setScale(scaleX, scaleY, updateNow); box.setAngle(angle, updateNow); -box.move(1, updateNow); +box.move(speed, updateNow); box.setOffset({ x, y }, updateNow); console.log(box.dirty); // true diff --git a/docs/index.html b/docs/index.html index 0c5c5445..860a7d31 100644 --- a/docs/index.html +++ b/docs/index.html @@ -18,7 +18,7 @@
Bodies possess various properties:
pos: Vector
, x: number
, y: number
.setPosition(x: number, y: number)
for teleport and move(speed: number)
for moving forward in direction of its angle.setScale(x: number, y: number)
for setting and scale: Vector
for getting scalesetAngle(radians: number)
for setting and angle: number
for getting and deg2rad(degrees: number)
to convert to radians.setOffset(offset: Vector)
for setting and offset: Vector
for getting offset from the body center.Manipulate body attributes and update the collision system:
-// if omitted updateNow is true
const updateNow = false;
// teleport
box.setPosition(x, y, updateNow);
box.setScale(scaleX, scaleY, updateNow);
box.setAngle(angle, updateNow);
box.move(1, updateNow);
box.setOffset({ x, y }, updateNow);
console.log(box.dirty); // true
box.updateBody(); // Update the body once, when all manipulations are done
console.log(box.dirty); // false
box.group = group; // Immediate effect, no body/system update needed
console.log(box.dirty); // false
+// if omitted updateNow is true
const updateNow = false;
// this should be time scaled, 1 for example
const speed = 1;
// teleport
box.setPosition(x, y, updateNow);
box.setScale(scaleX, scaleY, updateNow);
box.setAngle(angle, updateNow);
box.move(speed, updateNow);
box.setOffset({ x, y }, updateNow);
console.log(box.dirty); // true
box.updateBody(); // Update the body once, when all manipulations are done
console.log(box.dirty); // false
box.group = group; // Immediate effect, no body/system update needed
console.log(box.dirty); // false
Step 5: Collision Detection and Resolution
Detect collisions and respond accordingly:
diff --git a/package.json b/package.json
index 691fe2e2..b38ce2e3 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,13 @@
{
"name": "detect-collisions",
- "version": "9.9.3",
- "description": "detecting collisions between bodies: Points, Lines, Boxes, Polygons, Ellipses, Circles. RayCasting. Bodies have offset, rotation, scale, bbox padding, be static (non moving), be trigger bodies (non colliding).",
+ "version": "9.9.4",
+ "description": "Detect collisions between different shapes such as Points, Lines, Boxes, Polygons (including concave), Ellipses, and Circles. Features include RayCasting and support for offsets, rotation, scaling, bounding box padding, with options for static and trigger bodies (non-colliding).",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"start": "chef-express dist/demo --debug",
"test": "jest --silent --verbose --forceExit",
- "dev": "webpack serve --port 4200",
+ "dev": "webpack serve --port 3000",
"amend": "npm run precommit;git commit -a --am --no-edit",
"use-latest-quickselect-macos": "sed -i '' -e \"s_'quickselect'_'./quickselect'_g\" src/external/rbush.js",
"use-latest-quickselect-linux": "sed -i -r \"s_'quickselect'_'./quickselect'_g\" src/external/rbush.js",