@@ -47,9 +47,11 @@ var SeparateX = function (collisionInfo)
4747 var body1Immovable = ( body1 . physicsType === CONST . STATIC_BODY || body1 . immovable ) ;
4848 var body2Immovable = ( body2 . physicsType === CONST . STATIC_BODY || body2 . immovable ) ;
4949
50- console . log ( '' ) ;
51- console . log ( '%c X frame ' + body1 . world . _frame + ' ' , 'background-color: orange' ) ;
52- console . log ( 'body1:' , body1 . gameObject . name , 'vs body2:' , body2 . gameObject . name ) ;
50+ // console.log('');
51+ // console.log('%c X frame ' + body1.world._frame + ' ', 'background-color: orange');
52+ // console.log('body1:', body1.gameObject.name, 'vs body2:', body2.gameObject.name);
53+ // console.log('pre-GetOverlap bx = body1', body1.x, 'body2', body2.x);
54+ console . log ( 'x compare (PRE-SX):' , body1 . right , 'body2' , body2 . x , '=' , ( body1 . right - body2 . x ) ) ;
5355
5456 // console.log('pre-GetOverlap by = body1', body1.y, 'body2', body2.y);
5557 // console.log('pre-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
@@ -58,7 +60,7 @@ var SeparateX = function (collisionInfo)
5860 // console.log('post-GetOverlap by = body1', body1.y, 'body2', body2.y);
5961 // console.log('post-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
6062
61- console . log ( 'body1 overlaps body2 across the' , ( ( leftFace ) ? 'left' : 'right' ) , 'by' , overlap , 'px' ) ;
63+ // console.log('body1 overlaps body2 across the', ((leftFace) ? 'left' : 'right'), 'by', overlap, 'px');
6264
6365 // Can't separate two immovable bodies, or a body with its own custom separation logic
6466 if ( ! intersects || overlapOnly || ( body1Immovable && body2Immovable ) || body1 . customSeparateX || body2 . customSeparateX )
@@ -111,10 +113,10 @@ var SeparateX = function (collisionInfo)
111113 nx1 = avg + nv1 * bounce1 . x ;
112114 nx2 = avg + nv2 * bounce2 . x ;
113115
114- console . log ( 'resolution 1' ) ;
115- console . log ( 'pre-impact v = body1' , x1 , 'body2' , x2 ) ;
116- console . log ( 'post-impact v = body1' , nx1 , 'body2' , nx2 ) ;
117- console . log ( 'pre-impact x = body1' , body1 . gameObject . x , 'body2' , body2 . gameObject . x ) ;
116+ // console.log('resolution 1');
117+ // console.log('pre-impact v = body1', x1, 'body2', x2);
118+ // console.log('post-impact v = body1', nx1, 'body2', nx2);
119+ // console.log('pre-impact x = body1', body1.gameObject.x, 'body2', body2.gameObject.x);
118120 // console.log('wb = body1', body1.worldBlocked.right, 'body2', body2.worldBlocked.left);
119121
120122 // console.log('avg', avg);
@@ -179,7 +181,7 @@ var SeparateX = function (collisionInfo)
179181 var totalA = collisionInfo . shareX1 ;
180182 var totalB = collisionInfo . shareX2 ;
181183
182- console . log ( 'split at' , totalA , totalB , 'of' , overlap ) ;
184+ // console.log('split at', totalA, totalB, 'of', overlap);
183185
184186 if ( totalA === 0 && totalB === 0 && overlap !== 0 )
185187 {
@@ -210,20 +212,20 @@ var SeparateX = function (collisionInfo)
210212
211213 if ( nx1 !== 0 )
212214 {
213- // nx1 < 0 = Body1 is moving LEFT
214- // nx1 > 0 = Body1 is moving RIGHT
215+ // nx1 < 0 = Body1 is now moving LEFT
216+ // nx1 > 0 = Body1 is now moving RIGHT
215217
216218 if ( leftFace )
217219 {
218220 // The left of Body1 overlaps with the right of Body2
219221 if ( body2 . isBlockedLeft ( ) )
220222 {
221- console . log ( 'nx1 <> 0 leftface ' , body1 . x ) ;
223+ console . log ( 'nx1 <> 0 left block left ' , body1 . x ) ;
222224 body1 . setBlockedLeft ( collisionInfo , body2 ) ;
223225 }
224226 else
225227 {
226- console . log ( 'nx1 <> 0 leftface add' , body1 . x ) ;
228+ console . log ( 'nx1 <> 0 left add' , body1 . x ) ;
227229 body1 . x += body1 . getMoveX ( totalA ) ;
228230 }
229231 }
@@ -232,12 +234,12 @@ var SeparateX = function (collisionInfo)
232234 // The right of Body1 overlaps with the left of Body2
233235 if ( body2 . isBlockedRight ( ) )
234236 {
235- console . log ( 'nx1 <> 0 rightface right' , body1 . x ) ;
237+ console . log ( 'nx1 <> 0 right block right' , body1 . x ) ;
236238 body1 . setBlockedRight ( collisionInfo , body2 ) ;
237239 }
238240 else
239241 {
240- console . log ( 'nx1 <> 0 rightface add' , body1 . x ) ;
242+ console . log ( 'nx1 <> 0 right add' , body1 . x ) ;
241243 body1 . x += body1 . getMoveX ( totalA ) ;
242244 }
243245 }
@@ -251,35 +253,46 @@ var SeparateX = function (collisionInfo)
251253 }
252254 else if ( body1 . moves )
253255 {
254- // Body1 is stationary, but is under physics control
256+ console . log ( 'body1 stationary' , body1 . right ) ;
257+
258+ // Body1 is now stationary
255259
256260 if ( leftFace )
257261 {
258- // The top of Body1 overlaps with the bottom of Body2
259- if ( totalA !== 0 && ! body1 . isBlockedRight ( ) )
260- {
261- console . log ( 'body1 stationary leftface add' , body1 . x ) ;
262+ // console.log('The left of Body1 overlaps with the right of Body2');
263+ // console.log(totalA, body1.isBlockedLeft(), body1.isBlockedRight());
264+ // console.log(totalB, body2.isBlockedLeft(), body2.isBlockedRight());
265+
266+ // The left of Body1 overlaps with the right of Body2
267+ // if (totalA !== 0 && !body1.isBlockedRight())
268+ // {
269+ // console.log('body1 stationary leftface add', body1.x, 'totalA', totalA);
262270 body1 . x += body1 . getMoveX ( totalA ) ;
263- }
271+ // }
264272
265273 if ( body2 . isBlockedLeft ( ) )
266274 {
267- console . log ( 'body1 stationary leftface left' , body1 . x ) ;
275+ // console.log('body1 stationary leftface left', body1.x);
268276 body1 . setBlockedLeft ( collisionInfo , body2 ) ;
269277 }
270278 }
271279 else if ( rightFace )
272280 {
273- // The bottom of Body1 overlaps with the top of Body2
274- if ( totalA !== 0 && ! body1 . isBlockedRight ( ) )
275- {
276- console . log ( 'body1 stationary rightface add' , body1 . x ) ;
281+ // console.log('The right of Body1 overlaps with the left of Body2');
282+ // console.log(totalA, body1.isBlockedLeft(), body1.isBlockedRight());
283+ // console.log(totalB, body2.isBlockedLeft(), body2.isBlockedRight());
284+
285+ // The right of Body1 overlaps with the left of Body2
286+
287+ // if (totalA !== 0 && !body1.isBlockedLeft())
288+ // {
289+ // console.log('body1 stationary rightface add', body1.x);
277290 body1 . x += body1 . getMoveX ( totalA ) ;
278- }
291+ // }
279292
280293 if ( body2 . isBlockedRight ( ) )
281294 {
282- console . log ( 'body1 stationary rightface down' , body1 . x ) ;
295+ // console.log('body1 stationary rightface down', body1.x);
283296 body1 . setBlockedRight ( collisionInfo , body2 ) ;
284297 }
285298 }
@@ -328,34 +341,44 @@ var SeparateX = function (collisionInfo)
328341 }
329342 else if ( body2 . moves )
330343 {
344+ console . log ( 'body2 stationary' , body2 . x ) ;
345+
331346 // Body2 is stationary
332347 if ( leftFace )
333348 {
349+ // console.log('The left of Body1 overlaps with the right of Body2');
350+ // console.log(totalA, body1.isBlockedLeft(), body1.isBlockedRight());
351+ // console.log(totalB, body2.isBlockedLeft(), body2.isBlockedRight());
352+
334353 // The bottom of Body2 overlaps with the top of Body1
335- if ( totalB !== 0 && ! body2 . isBlockedRight ( ) )
336- {
337- console . log ( 'body2 stationary leftface add' , body2 . x ) ;
354+ // if (totalB !== 0 && !body2.isBlockedRight())
355+ // {
356+ // console.log('body2 stationary leftface add', body2.x);
338357 body2 . x += body2 . getMoveX ( totalB ) ;
339- }
358+ // }
340359
341360 if ( body1 . isBlockedRight ( ) )
342361 {
343- console . log ( 'body2 stationary leftface down' , body2 . x ) ;
362+ // console.log('body2 stationary leftface down', body2.x);
344363 body2 . setBlockedRight ( collisionInfo , body1 ) ;
345364 }
346365 }
347366 else if ( rightFace )
348367 {
368+ // console.log('The right of Body1 overlaps with the left of Body2');
369+ // console.log(totalA, body1.isBlockedLeft(), body1.isBlockedRight());
370+ // console.log(totalB, body2.isBlockedLeft(), body2.isBlockedRight());
371+
349372 // The top of Body2 overlaps with the bottom of Body1
350- if ( totalB !== 0 && ! body2 . isBlockedLeft ( ) )
351- {
352- console . log ( 'body2 stationary rightface add' , body2 . x ) ;
373+ // if (totalB !== 0 && !body2.isBlockedLeft())
374+ // {
375+ // console.log('body2 stationary rightface add', body2.x);
353376 body2 . x += body2 . getMoveX ( totalB ) ;
354- }
377+ // }
355378
356379 if ( body1 . isBlockedLeft ( ) )
357380 {
358- console . log ( 'body2 stationary rightface down' , body2 . x ) ;
381+ // console.log('body2 stationary rightface down', body2.x);
359382 body2 . setBlockedLeft ( collisionInfo , body1 ) ;
360383 }
361384 }
@@ -408,6 +431,11 @@ var SeparateX = function (collisionInfo)
408431 velocity1 . x = nx1 ;
409432 velocity2 . x = nx2 ;
410433
434+ // console.log('post-GetOverlap bx = body1', body1.x, 'body2', body2.x);
435+ // console.log('post-GetOverlap bs = body1', body1.right, 'body2', body2.right);
436+
437+ console . log ( 'x compare (POST-SX):' , body1 . right , 'body2' , body2 . x , '=' , ( body1 . right - body2 . x ) ) ;
438+
411439 // If we got this far then there WAS overlap, and separation is complete, so return true
412440 return true ;
413441} ;
0 commit comments