How to get local point inside a body where mouse click occurred in box2d?

Posted by humbleBee on Game Development See other posts from Game Development or by humbleBee
Published on 2011-03-05T05:36:04Z Indexed on 2011/03/05 7:32 UTC
Read the original article Hit count: 180

Filed under:
|

I need to find out the point inside a body, lets say a rectangular object, where the mouse was clicked on. I'm makin a game where the force will be applied depending on where the mouse was clicked on the body. Any ideas?

Will body.GetLocalPoint(b2vec2) work? I tried by passing the mouse coordinates when the click occurred when inside the body but if the body's position is (400,300) in world coordinates then for trace(body.GetLocalPoint(new b2vec2(mouseX,mouseY)).x); I get some value between 380 to 406 or something (eg. 401.6666666). I thought getLocalPoint will give something like x=-10 when clicked to the left of the centre of body or x=15 when clicked to the right.

Language is As3 btw.

© Game Development or respective owner

Related posts about actionscript-3

Related posts about box2d