Skip to content

Commit

Permalink
Merge pull request #79 from LeXXik/fix-teleport
Browse files Browse the repository at this point in the history
Update motion state on move
  • Loading branch information
LeXXik authored Aug 30, 2024
2 parents a8e6347 + 5e59e42 commit 0bfe31e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gamebop/physics",
"description": "Physics components for PlayCanvas engine",
"version": "0.3.0",
"version": "0.3.1",
"main": "dist/physics.min.mjs",
"author": "Gamebop",
"license": "MIT",
Expand Down
10 changes: 6 additions & 4 deletions src/physics/jolt/back/motion-state.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class MotionState {
constructor(body) {
this._body = body;

this._updatePosition(body);
this._updateRotation(body);
this.updatePosition();
this.updateRotation();
}

compute(alpha, stepped) {
Expand Down Expand Up @@ -105,7 +105,8 @@ class MotionState {
return this._rotation;
}

_updatePosition(body) {
updatePosition() {
const body = this._body;
const bodyPos = body.GetPosition();
const p = { x: bodyPos.GetX(), y: bodyPos.GetY(), z: bodyPos.GetZ() };

Expand All @@ -114,7 +115,8 @@ class MotionState {
this._oldPos = { x: p.x, y: p.y, z: p.z };
}

_updateRotation(body) {
updateRotation() {
const body = this._body;
const bodyRot = body.GetRotation();
const r = { x: bodyRot.GetX(), y: bodyRot.GetY(), z: bodyRot.GetZ(), w: bodyRot.GetW() };

Expand Down
6 changes: 6 additions & 0 deletions src/physics/jolt/back/operators/modifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ class Modifier {
} else {
backend.bodyInterface.SetPositionAndRotation(body.GetID(), jv, jq, Jolt.EActivation_Activate);
}

const ms = body.motionState;
if (ms) {
ms.updatePosition();
ms.updateRotation();
}
} catch (e) {
if ($_DEBUG) {
Debug.error(e);
Expand Down

0 comments on commit 0bfe31e

Please sign in to comment.