Debugging circle collision

This commit is contained in:
Richard Davey 2022-12-13 18:24:41 +00:00
parent 8f1979c0df
commit 4b4473394c

View file

@ -1395,6 +1395,7 @@ var World = new Class({
{ {
// We got a satisfactory result from the separateCircle method // We got a satisfactory result from the separateCircle method
result = true; result = true;
runSeparation = false;
} }
else else
{ {
@ -1589,28 +1590,6 @@ var World = new Class({
if (twoCircles) if (twoCircles)
{ {
if (!body1Immovable && !body2Immovable)
{
overlapX *= 0.5;
overlapY *= 0.5;
}
if (!body1Immovable || body1.pushable || deadlock)
{
body1.x -= overlapX;
body1.y -= overlapY;
body1.updateCenter();
}
if (!body2Immovable || body2.pushable || deadlock)
{
body2.x += overlapX;
body2.y += overlapY;
body2.updateCenter();
}
var dx = body1Center.x - body2Center.x; var dx = body1Center.x - body2Center.x;
var dy = body1Center.y - body2Center.y; var dy = body1Center.y - body2Center.y;
var d = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); var d = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
@ -1623,20 +1602,49 @@ var World = new Class({
p *= 2; p *= 2;
} }
console.log('circ vel', body1Velocity, body2Velocity, 'p', p, 'nxy', nx, ny);
if (!body1Immovable) if (!body1Immovable)
{ {
body1Velocity.x = (body1Velocity.x - p / body1.mass * nx); body1Velocity.x = (body1Velocity.x - p / body1.mass * nx);
body1Velocity.y = (body1Velocity.y - p / body1.mass * ny); body1Velocity.y = (body1Velocity.y - p / body1.mass * ny);
body1Velocity.multiply(body1.bounce);
console.log('body1', body1Velocity, 'y', body1.y);
} }
if (!body2Immovable) if (!body2Immovable)
{ {
body2Velocity.x = (body2Velocity.x + p / body2.mass * nx); body2Velocity.x = (body2Velocity.x + p / body2.mass * nx);
body2Velocity.y = (body2Velocity.y + p / body2.mass * ny); body2Velocity.y = (body2Velocity.y + p / body2.mass * ny);
body2Velocity.multiply(body2.bounce);
console.log('body2', body2Velocity, 'y', body2.y);
} }
body1Velocity.multiply(body1.bounce); if (!body1Immovable && !body2Immovable)
body2Velocity.multiply(body2.bounce); {
overlapX *= 0.5;
overlapY *= 0.5;
}
if (!body1Immovable)
{
body1.x -= overlapX;
body1.y -= overlapY;
body1.updateCenter();
console.log('body1 sep', body1.y);
}
if (!body2Immovable)
{
body2.x += overlapX;
body2.y += overlapY;
body2.updateCenter();
}
results.result = true; results.result = true;
} }