@@ -8,6 +8,7 @@ var CircleContains = require('../../geom/circle/Contains');
88var Class = require ( '../../utils/Class' ) ;
99var CONST = require ( './const' ) ;
1010var Events = require ( './events' ) ;
11+ var FuzzyEqual = require ( '../../math/fuzzy/Equal' ) ;
1112var FuzzyLessThan = require ( '../../math/fuzzy/LessThan' ) ;
1213var FuzzyGreaterThan = require ( '../../math/fuzzy/GreaterThan' ) ;
1314var RadToDeg = require ( '../../math/RadToDeg' ) ;
@@ -685,6 +686,15 @@ var Body = new Class({
685686 */
686687 this . blocked = { none : true , up : false , down : false , left : false , right : false , by : null } ;
687688
689+ /**
690+ * Whether this Body was blocked from moving in a given direction during the last step.
691+ *
692+ * @name Phaser.Physics.Arcade.Body#wasBlocked
693+ * @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision }
694+ * @since 3.17.0
695+ */
696+ this . wasBlocked = { none : true , up : false , down : false , left : false , right : false } ;
697+
688698 /**
689699 * Whether this Body is colliding with a tile or the world boundary.
690700 *
@@ -884,24 +894,25 @@ var Body = new Class({
884894 */
885895 preUpdate : function ( )
886896 {
887- var wasTouching = this . wasTouching ;
897+ console . log ( 'preUpdate' , this . wasBlocked . down ) ;
898+
888899 var touching = this . touching ;
889900 var blocked = this . blocked ;
890901 var worldBlocked = this . worldBlocked ;
891902
892- // Store and reset collision flags
893- wasTouching . none = touching . none ;
894- wasTouching . up = touching . up ;
895- wasTouching . down = touching . down ;
896- wasTouching . left = touching . left ;
897- wasTouching . right = touching . right ;
898-
899903 touching . none = true ;
900904 touching . up = false ;
901905 touching . down = false ;
902906 touching . left = false ;
903907 touching . right = false ;
904908
909+ blocked . by = null ;
910+ blocked . none = true ;
911+ blocked . up = false ;
912+ blocked . down = false ;
913+ blocked . left = false ;
914+ blocked . right = false ;
915+
905916 worldBlocked . none = true ;
906917 worldBlocked . left = false ;
907918 worldBlocked . right = false ;
@@ -922,22 +933,21 @@ var Body = new Class({
922933 this . position . x = sprite . x + sprite . scaleX * ( this . offset . x - sprite . displayOriginX ) ;
923934 this . position . y = sprite . y + sprite . scaleY * ( this . offset . y - sprite . displayOriginY ) ;
924935
925- if ( this . collideWorldBounds )
936+ if ( this . collideWorldBounds && this . checkWorldBounds ( ) )
926937 {
927- this . checkWorldBounds ( ) ;
938+ console . log ( 'preUpdate cwb' , worldBlocked . down , 'was' , this . wasBlocked . down ) ;
939+
940+ blocked . up = worldBlocked . up ;
941+ blocked . down = worldBlocked . down ;
942+ blocked . left = worldBlocked . left ;
943+ blocked . right = worldBlocked . right ;
944+ blocked . none = false ;
928945 }
929946 else
930947 {
931948 this . updateCenter ( ) ;
932949 }
933950
934- blocked . by = null ;
935- blocked . up = worldBlocked . up ;
936- blocked . down = worldBlocked . down ;
937- blocked . left = worldBlocked . left ;
938- blocked . right = worldBlocked . right ;
939- blocked . none = ( ! blocked . up && ! blocked . down && ! blocked . left && ! blocked . right ) ;
940-
941951 this . rotation = sprite . rotation ;
942952
943953 this . preRotation = this . rotation ;
@@ -962,6 +972,8 @@ var Body = new Class({
962972 */
963973 update : function ( delta )
964974 {
975+ console . log ( 'update' , this . wasBlocked . down ) ;
976+
965977 var velocity = this . velocity ;
966978 var position = this . position ;
967979
@@ -973,34 +985,72 @@ var Body = new Class({
973985 position . y += this . getMoveY ( velocity . y * delta ) ;
974986 }
975987
988+ console . log ( 'update2' , this . worldBlocked . down , 'was' , this . wasBlocked . down ) ;
989+
976990 // Calculate the delta
977991 this . _dx = position . x - this . prev . x ;
978992 this . _dy = position . y - this . prev . y ;
979993
980994 var worldBlocked = this . worldBlocked ;
981995
982996 // World Bounds check
983- if ( this . collideWorldBounds && ! worldBlocked . none )
997+ if ( this . collideWorldBounds )
984998 {
985- var bx = ( this . worldBounce ) ? - this . worldBounce . x : - this . bounce . x ;
986- var by = ( this . worldBounce ) ? - this . worldBounce . y : - this . bounce . y ;
987-
988- // Reverse the velocity for the bounce
999+ console . log ( 'update3' , this . wasBlocked . down , 'w' , this . worldBlocked . down , 'n' , this . worldBlocked . none ) ;
9891000
990- if ( ( worldBlocked . left && velocity . x < 0 ) || ( worldBlocked . right && velocity . x > 0 ) )
991- {
992- velocity . x *= bx ;
993- }
1001+ var wasBlocked = this . wasBlocked ;
9941002
995- if ( ( worldBlocked . down && velocity . y > 0 ) || ( worldBlocked . up && velocity . y < 0 ) )
1003+ if ( ! worldBlocked . none )
9961004 {
997- velocity . y *= by ;
1005+ var bx = ( this . worldBounce ) ? - this . worldBounce . x : - this . bounce . x ;
1006+ var by = ( this . worldBounce ) ? - this . worldBounce . y : - this . bounce . y ;
1007+
1008+ // Reverse the velocity for the bounce
1009+
1010+ // if ((worldBlocked.left && velocity.x < 0) || (worldBlocked.right && velocity.x > 0))
1011+ // {
1012+ // velocity.x *= bx;
1013+ // }
1014+
1015+ console . log ( worldBlocked . down , wasBlocked . down ) ;
1016+
1017+ if ( worldBlocked . down && velocity . y > 0 )
1018+ {
1019+ velocity . y *= by ;
1020+
1021+ // vy should now be negative
1022+
1023+ console . log ( 'down' , velocity . y , this . _dy , wasBlocked . down ) ;
1024+
1025+ // if (this._dy < -this.minBounceVelocity.y)
1026+ // {
1027+ // velocity.y = 0;
1028+ // }
1029+ }
1030+ else if ( worldBlocked . up && velocity . y < 0 )
1031+ {
1032+ // vy should now be positive
1033+ velocity . y *= by ;
1034+
1035+ console . log ( 'up' , velocity . y , this . _dy , wasBlocked . up ) ;
1036+
1037+ // if (this._dy < this.minBounceVelocity.y)
1038+ // {
1039+ // velocity.y = 0;
1040+ // }
1041+ }
9981042 }
999-
1043+
10001044 if ( this . onWorldBounds )
10011045 {
10021046 this . world . emit ( Events . WORLD_BOUNDS , this , worldBlocked . up , worldBlocked . down , worldBlocked . left , worldBlocked . right ) ;
10031047 }
1048+
1049+ wasBlocked . none = worldBlocked . none ;
1050+ wasBlocked . up = worldBlocked . up ;
1051+ wasBlocked . down = worldBlocked . down ;
1052+ wasBlocked . left = worldBlocked . left ;
1053+ wasBlocked . right = worldBlocked . right ;
10041054 }
10051055
10061056 this . updateCenter ( ) ;
@@ -1086,6 +1136,26 @@ var Body = new Class({
10861136 gameObject . angle += this . deltaZ ( ) ;
10871137 }
10881138
1139+ // Store collision flags
1140+ var wasTouching = this . wasTouching ;
1141+ var wasBlocked = this . wasBlocked ;
1142+ var touching = this . touching ;
1143+ var worldBlocked = this . worldBlocked ;
1144+
1145+ wasTouching . none = touching . none ;
1146+ wasTouching . up = touching . up ;
1147+ wasTouching . down = touching . down ;
1148+ wasTouching . left = touching . left ;
1149+ wasTouching . right = touching . right ;
1150+
1151+ console . log ( 'postUpdate' , worldBlocked . down , 'was' , wasBlocked . down ) ;
1152+
1153+ // wasBlocked.none = worldBlocked.none;
1154+ // wasBlocked.up = worldBlocked.up;
1155+ // wasBlocked.down = worldBlocked.down;
1156+ // wasBlocked.left = worldBlocked.left;
1157+ // wasBlocked.right = worldBlocked.right;
1158+
10891159 this . prev . x = this . position . x ;
10901160 this . prev . y = this . position . y ;
10911161 } ,
@@ -1900,14 +1970,20 @@ var Body = new Class({
19001970
19011971 if ( amount < 0 && check . up && pos . y + amount < bounds . y )
19021972 {
1973+ worldBlocked . none = false ;
19031974 worldBlocked . up = true ;
1975+
19041976 blocked . up = true ;
1977+
19051978 return amount - ( ( pos . y + amount ) - bounds . y ) ;
19061979 }
19071980 else if ( amount > 0 && check . down && this . bottom + amount > bounds . bottom )
19081981 {
1982+ worldBlocked . none = false ;
19091983 worldBlocked . down = true ;
1984+
19101985 blocked . down = true ;
1986+
19111987 return amount - ( ( this . bottom + amount ) - bounds . bottom ) ;
19121988 }
19131989 }
0 commit comments