Skip to content

Commit d59617a

Browse files
committed
Never ending debugging ahoy.
1 parent 5485c07 commit d59617a

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,12 +1144,12 @@ var Body = new Class({
11441144
if (newVelocityY > 0 && (newVelocityY < gravityY || FuzzyLessThan(newVelocityY, gravityY, 2)))
11451145
{
11461146
velocity.y = 0;
1147-
console.log('rebound up too small, zeroing', newVelocityY, gravityY);
1147+
console.log(this.gameObject.name, 'rebound up too small, zeroing', newVelocityY, gravityY);
11481148
}
11491149
else
11501150
{
11511151
velocity.y *= -by;
1152-
console.log('rebounded up', newVelocityY, gravityY);
1152+
console.log(this.gameObject.name, 'rebounded up', newVelocityY, gravityY);
11531153

11541154
if (this.onWorldBounds)
11551155
{
@@ -1163,12 +1163,12 @@ var Body = new Class({
11631163
if (newVelocityY < 0 && (newVelocityY > gravityY || FuzzyGreaterThan(newVelocityY, gravityY, 2)))
11641164
{
11651165
velocity.y = 0;
1166-
console.log('rebound down too small, zeroing', newVelocityY, gravityY);
1166+
console.log(this.gameObject.name, 'rebound down too small, zeroing', newVelocityY, gravityY);
11671167
}
11681168
else
11691169
{
11701170
velocity.y *= -by;
1171-
console.log('rebounded down', newVelocityY, gravityY);
1171+
console.log(this.gameObject.name, 'rebounded down', newVelocityY, gravityY);
11721172

11731173
if (this.onWorldBounds)
11741174
{

src/physics/arcade/SeparateY.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,35 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
7676
var mass1 = body1.mass;
7777
var mass2 = body2.mass;
7878

79-
var nv1 = Math.sqrt((v2 * v2 * mass2) / mass1) * ((v2 > 0) ? 1 : -1);
80-
var nv2 = Math.sqrt((v1 * v1 * mass1) / mass2) * ((v1 > 0) ? 1 : -1);
79+
var bnv1 = Math.sqrt((v2 * v2 * mass2) / mass1) * ((v2 > 0) ? 1 : -1);
80+
var bnv2 = Math.sqrt((v1 * v1 * mass1) / mass2) * ((v1 > 0) ? 1 : -1);
8181

82-
var avg = (nv1 + nv2) * 0.5;
82+
var avg = (bnv1 + bnv2) * 0.5;
83+
84+
var nv1 = bnv1;
85+
var nv2 = bnv2;
8386

8487
nv1 -= avg;
8588
nv2 -= avg;
8689

8790
ny1 = avg + nv1 * bounce1.y;
8891
ny2 = avg + nv2 * bounce2.y;
8992

90-
console.log('*1', ny1, ny2, 'vs', v1, v2, 'avg', avg, 'nv', nv1, nv2, 'bounce', body1.bounce.y, body2.bounce.y, 'delta', body1.deltaY(), body2.deltaY());
93+
// var total = v1 - v2;
94+
// ny1 = (((mass1 - mass2) * v1 + 2 * mass1 * v1) / (mass1 + mass2)) * bounce1.y;
95+
// ny2 = (total + ny1) * bounce2.y;
96+
// console.log('*1', ny1, ny2, 'vs', v1, v2, 'delta', body1.deltaY(), body2.deltaY());
97+
98+
console.log('resolution');
99+
console.log('body1', ny1, 'body2', ny2);
100+
console.log('v1', v1, 'v2', v2);
101+
console.log('avg', avg);
102+
console.log('nv', nv1, nv2);
103+
console.log('sqrt', bnv1, bnv2);
104+
console.log('delta', body1.deltaY(), body2.deltaY());
105+
106+
// console.log('*1', ny1, ny2, 'vs', v1, v2, 'avg', avg, 'nv', nv1, nv2, 'bounce', body1.bounce.y, body2.bounce.y, 'delta', body1.deltaY(), body2.deltaY());
107+
// console.log('*1', ny1, ny2, 'vs', v1, v2, 'avg', avg, 'nv', nv1, nv2, 'bounce', body1.bounce.y, body2.bounce.y, 'delta', body1.deltaY(), body2.deltaY());
91108
}
92109
else if (body1Immovable)
93110
{
@@ -154,10 +171,12 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
154171
if (worldBlocked2.up)
155172
{
156173
body1.setWorldBlockedUp(body2.bottom);
174+
console.log('ny1 < 0 topface up', body1.y);
157175
}
158176
else
159177
{
160178
body1.y += totalA;
179+
console.log('ny1 < 0 topface add', body1.y);
161180
}
162181
}
163182
else if (bottomFace)
@@ -166,17 +185,20 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
166185
if (worldBlocked2.down)
167186
{
168187
body1.setWorldBlockedDown(body2.y);
188+
console.log('ny1 < 0 bottomface down', body1.y);
169189
}
170190
else
171191
{
172192
body1.y += totalA;
193+
console.log('ny1 < 0 bottomface add', body1.y);
173194
}
174195
}
175196

176197
// If Body1 cannot move up, it doesn't matter what new velocity it has.
177198
if (worldBlocked1.up && body1.sleeping)
178199
{
179200
ny1 = 0;
201+
console.log('ny1 < 0 zero sleep');
180202
}
181203
}
182204
else if (ny1 > 0)
@@ -189,10 +211,12 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
189211
if (worldBlocked2.up)
190212
{
191213
body1.setWorldBlockedUp(body2.bottom);
214+
console.log('ny1 > 0 topface up', body1.y);
192215
}
193216
else
194217
{
195218
body1.y += totalA;
219+
console.log('ny1 > 0 topface add', body1.y);
196220
}
197221
}
198222
else if (bottomFace)
@@ -201,26 +225,30 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
201225
if (worldBlocked2.down)
202226
{
203227
body1.setWorldBlockedDown(body2.y);
228+
console.log('ny1 > 0 bottomface down', body1.y);
204229
}
205230
else
206231
{
207232
body1.y += totalA;
233+
console.log('ny1 > 0 bottomface add', body1.y);
208234
}
209235
}
210236

211237
// If Body1 cannot move down, it doesn't matter what new velocity it has.
212238
if (worldBlocked1.down && body1.sleeping)
213239
{
214240
ny1 = 0;
241+
console.log('ny1 > 0 zero sleep');
215242
}
216243
}
217244
else
218245
{
219246
// Body1 is stationary
220247
body1.y += totalA;
248+
console.log('body1 stationary', body1.y);
221249
}
222250

223-
if (body2.deltaY() < 0)
251+
if (ny2 < 0)
224252
{
225253
// Body2 is moving UP
226254

@@ -230,10 +258,12 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
230258
if (worldBlocked1.down)
231259
{
232260
body2.setWorldBlockedDown(body1.y);
261+
console.log('ny2 < 0 topface down', body2.y);
233262
}
234263
else
235264
{
236265
body2.y += totalB;
266+
console.log('ny2 < 0 topface add', body2.y);
237267
}
238268
}
239269
else if (bottomFace)
@@ -242,20 +272,23 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
242272
if (worldBlocked1.up)
243273
{
244274
body2.setWorldBlockedUp(body1.bottom);
275+
console.log('ny2 < 0 bottomface down', body2.y);
245276
}
246277
else
247278
{
248279
body2.y += totalB;
280+
console.log('ny2 < 0 bottomface add', body2.y);
249281
}
250282
}
251283

252284
// If Body2 cannot move up, it doesn't matter what new velocity it has.
253285
if (worldBlocked2.up && body2.sleeping)
254286
{
255287
ny2 = 0;
288+
console.log('ny2 < 0 zero sleep');
256289
}
257290
}
258-
else if (body2.deltaY() > 0)
291+
else if (ny2 > 0)
259292
{
260293
// Body2 is moving DOWN
261294

@@ -265,10 +298,12 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
265298
if (worldBlocked1.down)
266299
{
267300
body2.setWorldBlockedDown(body1.y);
301+
console.log('ny2 > 0 topface down', body2.y);
268302
}
269303
else
270304
{
271305
body2.y += totalB;
306+
console.log('ny2 > 0 topface add', body2.y);
272307
}
273308
}
274309
else if (bottomFace)
@@ -277,23 +312,27 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
277312
if (worldBlocked1.up)
278313
{
279314
body2.setWorldBlockedUp(body1.bottom);
315+
console.log('ny2 > 0 bottomface up', body2.y);
280316
}
281317
else
282318
{
283-
body1.y += totalA;
319+
body2.y += totalB;
320+
console.log('ny2 > 0 bottomface add', body2.y);
284321
}
285322
}
286323

287324
// If Body2 cannot move down, it doesn't matter what new velocity it has.
288325
if (worldBlocked2.down && body2.sleeping)
289326
{
290327
ny2 = 0;
328+
console.log('ny2 > 0 zero sleep');
291329
}
292330
}
293331
else
294332
{
295333
// Body2 is stationary
296334
body2.y += totalB;
335+
console.log('body2 stationary', body2.y);
297336
}
298337

299338
console.log('postb', worldBlocked1.up, worldBlocked1.down, worldBlocked2.up, worldBlocked2.down);
@@ -345,6 +384,8 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
345384
// body1.x += body1.getMoveX((body2.deltaX()) * body2.friction.x, true);
346385
// }
347386

387+
console.log('---', Date.now());
388+
348389
// If we got this far then there WAS overlap, and separation is complete, so return true
349390
return true;
350391
};

0 commit comments

Comments
 (0)