fix: physics scaling
This commit is contained in:
parent
fca289642b
commit
cd8b59c218
|
@ -15,7 +15,7 @@ const g = typeof window !== 'undefined' ? window : typeof global !== 'undefined'
|
|||
if (g) {
|
||||
g.decomp = require('poly-decomp');
|
||||
}
|
||||
|
||||
// Translate "real" coordinates to physics coordinates.
|
||||
const SCALE = 1;
|
||||
|
||||
export class Body extends AbstractBody {
|
||||
|
@ -50,9 +50,10 @@ export class Body extends AbstractBody {
|
|||
constructor(shape) {
|
||||
super(shape);
|
||||
const [body, position, origin] = this.constructor.bodyFromShape(shape);
|
||||
// Set body first, then origin, then position. Order important.
|
||||
this.matterBody = body;
|
||||
this.origin = origin;
|
||||
this.position = position;
|
||||
this.position = Vector.scale(position, SCALE);
|
||||
this.constructor.associateBody(this.matterBody, this);
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ export class Body extends AbstractBody {
|
|||
const children = [];
|
||||
for (const child of shape) {
|
||||
const [body, position, origin] = this.bodyFromShape(child);
|
||||
const [x, y] = Vector.add(Vector.scale(position, 1 / SCALE), origin);
|
||||
const [x, y] = Vector.add(position, origin);
|
||||
MatterBody.setPosition(body, {x, y});
|
||||
children.push(body);
|
||||
}
|
||||
|
@ -97,7 +98,7 @@ export class Body extends AbstractBody {
|
|||
MatterBody.setPosition(body, Vertices.centre(vertices));
|
||||
}
|
||||
const {x, y} = body.position;
|
||||
return [body, shapePosition, Vector.scale([x, y], SCALE)];
|
||||
return [body, shapePosition, [x, y]];
|
||||
}
|
||||
else if (shape instanceof RectangleShape) {
|
||||
const [width, height] = Vector.scale(shape.size, 1 / SCALE);
|
||||
|
|
Loading…
Reference in New Issue
Block a user