Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions demos/buoyancy.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
} else if(aabb.lowerBound[1] < planePosition[1]){
// Partially submerged
var width = aabb.upperBound[0] - aabb.lowerBound[0];
var height = 0 - aabb.lowerBound[1];
var height = planePosition[1] - aabb.lowerBound[1];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was caught by this issue as well when I was running my own implementation.

areaUnderWater = width * height;
p2.vec2.set(centerOfBouyancy, aabb.lowerBound[0] + width / 2, aabb.lowerBound[1] + height / 2);
} else {
Expand All @@ -95,15 +95,15 @@

// Compute lift force
p2.vec2.subtract(liftForce, planePosition, centerOfBouyancy);
p2.vec2.scale(liftForce, liftForce, areaUnderWater * k);
p2.vec2.scale(liftForce, liftForce, areaUnderWater * k / body.shapes.length);
liftForce[0] = 0;

// Make center of bouycancy relative to the body
p2.vec2.subtract(centerOfBouyancy,centerOfBouyancy,body.position);

// Viscous force
body.getVelocityAtPoint(v, centerOfBouyancy);
p2.vec2.scale(viscousForce, v, -c);
p2.vec2.scale(viscousForce, v, -c / body.shapes.length);

// Apply forces
body.applyForce(viscousForce,centerOfBouyancy);
Expand Down