File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 445445 Body . setVertices ( bodyE , bodyE . vertices ) ;
446446 }
447447
448- // make bodyA move up and down and rotate constantly
449- Body . setPosition ( bodyA , { x : 100 , y : 300 + 100 * Math . sin ( _engine . timing . timestamp * 0.005 ) } ) ;
450- Body . rotate ( bodyA , 0.02 ) ;
448+ // make bodyA move up and down
449+ // body is static so must manually update velocity for friction to work
450+ var py = 300 + 100 * Math . sin ( _engine . timing . timestamp * 0.002 ) ;
451+ Body . setVelocity ( bodyA , { x : 0 , y : py - bodyA . position . y } ) ;
452+ Body . setPosition ( bodyA , { x : 100 , y : py } ) ;
451453
452454 // make compound body move up and down and rotate constantly
453- Body . setPosition ( compound , { x : 600 , y : 300 + 100 * Math . sin ( _engine . timing . timestamp * 0.005 ) } ) ;
455+ Body . setVelocity ( compound , { x : 0 , y : py - compound . position . y } ) ;
456+ Body . setAngularVelocity ( compound , 0.02 ) ;
457+ Body . setPosition ( compound , { x : 600 , y : py } ) ;
454458 Body . rotate ( compound , 0.02 ) ;
455459
456460 // every 1.5 sec
You can’t perform that action at this time.
0 commit comments