@@ -213,21 +213,24 @@ var Body = {};
213213 * @param {bool } isStatic
214214 */
215215 Body . setStatic = function ( body , isStatic ) {
216- body . isStatic = isStatic ;
217-
218- if ( isStatic ) {
219- body . restitution = 0 ;
220- body . friction = 1 ;
221- body . mass = body . inertia = body . density = Infinity ;
222- body . inverseMass = body . inverseInertia = 0 ;
223-
224- body . positionPrev . x = body . position . x ;
225- body . positionPrev . y = body . position . y ;
226- body . anglePrev = body . angle ;
227- body . angularVelocity = 0 ;
228- body . speed = 0 ;
229- body . angularSpeed = 0 ;
230- body . motion = 0 ;
216+ for ( var i = 0 ; i < body . parts . length ; i ++ ) {
217+ var part = body . parts [ i ] ;
218+ part . isStatic = isStatic ;
219+
220+ if ( isStatic ) {
221+ part . restitution = 0 ;
222+ part . friction = 1 ;
223+ part . mass = part . inertia = part . density = Infinity ;
224+ part . inverseMass = part . inverseInertia = 0 ;
225+
226+ part . positionPrev . x = part . position . x ;
227+ part . positionPrev . y = part . position . y ;
228+ part . anglePrev = part . angle ;
229+ part . angularVelocity = 0 ;
230+ part . speed = 0 ;
231+ part . angularSpeed = 0 ;
232+ part . motion = 0 ;
233+ }
231234 }
232235 } ;
233236
@@ -589,10 +592,12 @@ var Body = {};
589592 properties . mass += part . mass ;
590593 properties . area += part . area ;
591594 properties . inertia += part . inertia ;
592- properties . centre = Vector . add ( properties . centre , Vector . mult ( part . position , part . mass ) ) ;
595+ properties . centre = Vector . add ( properties . centre ,
596+ Vector . mult ( part . position , part . mass !== Infinity ? part . mass : 1 ) ) ;
593597 }
594598
595- properties . centre = Vector . div ( properties . centre , properties . mass ) ;
599+ properties . centre = Vector . div ( properties . centre ,
600+ properties . mass !== Infinity ? properties . mass : body . parts . length ) ;
596601
597602 return properties ;
598603 } ;
0 commit comments