From d0a5621d5dc9265d4da005f1b40bf6aa831919d9 Mon Sep 17 00:00:00 2001 From: 1AlbertChen Date: Sat, 27 Nov 2021 15:02:20 +0800 Subject: [PATCH 1/2] added mesh initial velocity setter --- src/components/physics/useCannon.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/physics/useCannon.js b/src/components/physics/useCannon.js index 74c98ce..5a7b4b6 100644 --- a/src/components/physics/useCannon.js +++ b/src/components/physics/useCannon.js @@ -111,7 +111,12 @@ export default function useCannon(options) { const mass = mesh.userData.mass ? mesh.userData.mass : 0 const damping = mesh.userData.damping ? mesh.userData.damping : 0.01 - const body = new Body({ shape, position, quaternion, mass, linearDamping: damping, angularDamping: damping }) + const velocity = mesh.userData.velocity ? new Vec3( + mesh.userData.velocity.x, + mesh.userData.velocity.y, + mesh.userData.velocity.z) : new Vec3(0, 0, 0) + + const body = new Body({ shape, position, quaternion, velocity, mass, linearDamping: damping, angularDamping: damping }) world.addBody(body) mesh.userData.body = body From 050df4073cc91c94b4c0a22bfc5164669cc1919f Mon Sep 17 00:00:00 2001 From: 1AlbertChen Date: Sat, 27 Nov 2021 15:05:20 +0800 Subject: [PATCH 2/2] added mesh initial velocity --- src/components/physics/useCannon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/physics/useCannon.js b/src/components/physics/useCannon.js index 5a7b4b6..02d3a43 100644 --- a/src/components/physics/useCannon.js +++ b/src/components/physics/useCannon.js @@ -116,7 +116,7 @@ export default function useCannon(options) { mesh.userData.velocity.y, mesh.userData.velocity.z) : new Vec3(0, 0, 0) - const body = new Body({ shape, position, quaternion, velocity, mass, linearDamping: damping, angularDamping: damping }) + const body = new Body({ shape, position, velocity, quaternion, mass, linearDamping: damping, angularDamping: damping }) world.addBody(body) mesh.userData.body = body