This project has moved. For the latest updates, please go here.

Get body location on screen?

Topics: Developer Forum
Sep 19, 2011 at 10:25 PM


I can't for my life find out how to get a body's current position on screen! Can anyone give me a hand? :)

What' I'm trying to achieve is to get the angle from my avatar (which is being tracked by the camera - so he's around the center of the screen most of the time) to the cursor.

This is what I've got so far:

Vector2 target = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) - new Vector2(<BodyOnScreen.X?>, <BodyOnScreen.Y?>)

double angle = Math.Atan2(target.Y, target.X);

Any idea how I can get these coordinates/an alternate (perhaps better) way of doing this?


(My avatar has arms that I want pointing towards the cursor at some times - hence the angle)

Sep 20, 2011 at 12:20 AM

If you are using Camera2D that comes with the farseer samples you can convert the mouse coordinates to world by calling ConvertScreenToWorld. It unprojects the vector using the GraphicsDevice and camera matrices.

Sep 21, 2011 at 8:52 PM

Thank you thank you thank you! :)