[ts] Port: Scale physics constraint limits with skeleton scale. See #2576.

This commit is contained in:
Davide Tantillo 2024-07-12 09:00:01 +02:00
parent be3aa5f70e
commit cbed5fbf40

View File

@ -136,9 +136,10 @@ export class PhysicsConstraint implements Updatable {
this.reset(); this.reset();
// Fall through. // Fall through.
case Physics.update: case Physics.update:
const skeleton = this.skeleton;
const delta = Math.max(this.skeleton.time - this.lastTime, 0); const delta = Math.max(this.skeleton.time - this.lastTime, 0);
this.remaining += delta; this.remaining += delta;
this.lastTime = this.skeleton.time; this.lastTime = skeleton.time;
const bx = bone.worldX, by = bone.worldY; const bx = bone.worldX, by = bone.worldY;
if (this._reset) { if (this._reset) {
@ -146,16 +147,18 @@ export class PhysicsConstraint implements Updatable {
this.ux = bx; this.ux = bx;
this.uy = by; this.uy = by;
} else { } else {
let a = this.remaining, i = this.inertia, q = this.data.limit * delta, t = this.data.step, f = this.skeleton.data.referenceScale, d = -1; let a = this.remaining, i = this.inertia, t = this.data.step, f = this.skeleton.data.referenceScale, d = -1;
let qx = this.data.limit * delta, qy = qx * skeleton.scaleY;
qx *= skeleton.scaleX;
if (x || y) { if (x || y) {
if (x) { if (x) {
const u = (this.ux - bx) * i; const u = (this.ux - bx) * i;
this.xOffset += u > q ? q : u < -q ? -q : u; this.xOffset += u > qx ? qx : u < -qx ? -qx : u;
this.ux = bx; this.ux = bx;
} }
if (y) { if (y) {
const u = (this.uy - by) * i; const u = (this.uy - by) * i;
this.yOffset += u > q ? q : u < -q ? -q : u; this.yOffset += u > qy ? qy : u < -qy ? -qy : u;
this.uy = by; this.uy = by;
} }
if (a >= t) { if (a >= t) {
@ -181,14 +184,14 @@ export class PhysicsConstraint implements Updatable {
if (rotateOrShearX || scaleX) { if (rotateOrShearX || scaleX) {
let ca = Math.atan2(bone.c, bone.a), c = 0, s = 0, mr = 0; let ca = Math.atan2(bone.c, bone.a), c = 0, s = 0, mr = 0;
let dx = this.cx - bone.worldX, dy = this.cy - bone.worldY; let dx = this.cx - bone.worldX, dy = this.cy - bone.worldY;
if (dx > q) if (dx > qx)
dx = q; dx = qx;
else if (dx < -q) // else if (dx < -qx) //
dx = -q; dx = -qx;
if (dy > q) if (dy > qy)
dy = q; dy = qy;
else if (dy < -q) // else if (dy < -qy) //
dy = -q; dy = -qy;
if (rotateOrShearX) { if (rotateOrShearX) {
mr = (this.data.rotate + this.data.shearX) * mix; mr = (this.data.rotate + this.data.shearX) * mix;
let r = Math.atan2(dy + this.ty, dx + this.tx) - ca - this.rotateOffset * mr; let r = Math.atan2(dy + this.ty, dx + this.tx) - ca - this.rotateOffset * mr;