Skip to content

Commit 8312bbe

Browse files
authored
Fix 3D Physics "apply force/impulse toward position" action (#7600)
1 parent bb77a71 commit 8312bbe

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,11 +1470,11 @@ namespace gdjs {
14701470
const deltaX = towardX - body.GetPosition().GetX();
14711471
const deltaY = towardY - body.GetPosition().GetY();
14721472
const deltaZ = towardZ - body.GetPosition().GetZ();
1473-
const distance = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
1474-
if (distance === 0) {
1473+
const distanceSq = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
1474+
if (distanceSq === 0) {
14751475
return;
14761476
}
1477-
const ratio = length / distance;
1477+
const ratio = length / Math.sqrt(distanceSq);
14781478

14791479
this._sharedData.bodyInterface.AddForce(
14801480
body.GetID(),
@@ -1540,11 +1540,11 @@ namespace gdjs {
15401540
const deltaX = towardX - originX;
15411541
const deltaY = towardY - originY;
15421542
const deltaZ = towardZ - originZ;
1543-
const distance = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
1544-
if (distance === 0) {
1543+
const distanceSq = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
1544+
if (distanceSq === 0) {
15451545
return;
15461546
}
1547-
const ratio = length / distance;
1547+
const ratio = length / Math.sqrt(distanceSq);
15481548

15491549
this._sharedData.bodyInterface.AddImpulse(
15501550
body.GetID(),

0 commit comments

Comments
 (0)