|
121 | 121 |
|
122 | 122 |
|
123 | 123 | // Allow pass through platforms from below
|
124 |
| - var passThroughBody; |
| 124 | + var passThroughBody, currentPlatform; |
125 | 125 |
|
126 | 126 | world.on('beginContact', function (evt){
|
127 | 127 | if(evt.bodyA !== characterBody && evt.bodyB !== characterBody) return;
|
128 | 128 | var otherBody = evt.bodyA === characterBody ? evt.bodyB : evt.bodyA;
|
129 |
| - if(platforms.indexOf(otherBody) !== -1 && otherBody.position[1] > characterBody.position[1]){ |
| 129 | + var platformIndex = platforms.indexOf(otherBody); |
| 130 | + if(platformIndex != -1 && otherBody.position[1] > characterBody.position[1]){ |
130 | 131 | passThroughBody = otherBody;
|
| 132 | + } else if(platformIndex != -1){ |
| 133 | + currentPlatform = platforms[platformIndex]; |
131 | 134 | }
|
132 | 135 | });
|
133 | 136 |
|
134 | 137 | // Disable any equations between the current passthrough body and the character
|
135 | 138 | world.on('preSolve', function (evt){
|
| 139 | + if(currentPlatform) characterBody.velocity[0] += currentPlatform.velocity[0]; |
136 | 140 | for(var i=0; i<evt.contactEquations.length; i++){
|
137 | 141 | var eq = evt.contactEquations[i];
|
138 | 142 | if((eq.bodyA === characterBody && eq.bodyB === passThroughBody) || eq.bodyB === characterBody && eq.bodyA === passThroughBody){
|
|
151 | 155 | if((evt.bodyA === characterBody && evt.bodyB === passThroughBody) || evt.bodyB === characterBody && evt.bodyA === passThroughBody){
|
152 | 156 | passThroughBody = undefined;
|
153 | 157 | }
|
| 158 | + if(evt.bodyA !== characterBody && evt.bodyB !== characterBody) return; |
| 159 | + var otherBody = evt.bodyA === characterBody ? evt.bodyB : evt.bodyA; |
| 160 | + var platformIndex = platforms.indexOf(otherBody); |
| 161 | + if(otherBody == currentPlatform){ |
| 162 | + currentPlatform = null; |
| 163 | + } |
154 | 164 | });
|
155 | 165 |
|
156 | 166 | }
|
|
0 commit comments