AS3: Moving a Starling object with Nape

For those who may not have been able to find anything about this or just not figured it out yet, here is an effective way to animate the coordinates of a Starling Movieclip while keeping the Nape body physics in tact:


setup body.graphic as a Starling Object

animate the body.graphic within an EnterFrameEvent:

public function animate(EnterFrameEvent:Event):void {      
     body.graphic.x +=  10; 
     body.graphic.y += 10; 
     //here is where the black magic begins      


now the update:

public static function updatePos(body:Body):void {      
     body.velocity.x = (body.graphic.x - body.position.x) / GameSpace.timeStep;     
     body.velocity.y = (body.graphic.y - body.position.y) /  GameSpace.timeStep;      
     //timeStep is determined by you, so change and tweak it until you get it right     
     //I am currently using: GameSpace.timeStep = 1 / 90; 


This will update the body KINEMATIC or DYNAMIC body along with the associated body.graphic.
Keep in mind that your space.step will need to be updated as well as the amount of space covered by your EnterFrameEvnt to get the right balance of movement of body, speed and collision/sensor checks…


- Nape moves me