nape making a body follow the mouse

692 views Asked by At

I have a dynamic body in name and want to make its x position follow the mouse, is this possible.

player = new Body(BodyType.DYNAMIC);
        player.shapes.add(new Polygon(Polygon.rect(400, 350, 100, 150)));
        player.shapes.add(new Polygon(Polygon.rect(435, 450, 20, 150)));
        player.shapes.add(new Polygon(Polygon.rect(380, 600, 150, 20)));
        player_mc = new MovieClip(Assets.tb.getTextures("player"));
        player.userData.graphic = player_mc;
        player.space = space;
        addChild(player.userData.graphic);
1

There are 1 answers

0
deltaluca On BEST ANSWER

The suggested way would be to use a constraint.

See how it is done in the FixedDragging sample: http://napephys.com/samples.html#swf-FixedDragging (View source with .as/.hx tabs at top)