문제

I'm trying to learn how to use box2dweb and would like to have an object (a circle in this case) follow the mouse at all times, not just when dragging. The idea being it could be used for an air hockey type game where the circle is your paddle.

However circle doesn't attach itself properly to the mouse, instead it swings around the point where the mouse cursor is and behaves more like a distance joint would if one of the objects were the mouse cursor.

I can't tell what I'm doing wrong but I'm still new to this so any help would be appreciated.

You can see the code I have so far (based on the demo code) here: http://jsbin.com/ejafoj/1/edit

도움이 되었습니까?

해결책

Managed to figure this out, my problem was a misunderstanding of the difference between the mousejoint definition target and the mousejoint target. I needed to set the definition target to the center of the ball and not the mouse cursor. Once I did that it worked perfectly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top