BGE mouse drag. How to get world coordinates?

I have an ortho camera setup that is viewing a plane that is perpendicular to the camera view (i.e. a flat background). I’m trying to get the mouse coordinates and convert those a location on the plane that is under the mouse cursor.

I didn’t see any methods in the Camera object that would cast from screen coordinates and tell me the World location on the hit target. Camera.getScreenRay(…) seems like it is almost what I want but it returns a GameObject, not the coordinate where the ray hit the GameObject.

I want to be able to drag objects around with my mouse. So I think I just need to update my dragged object’s location to be the same at the point hitting my plane from the mouse cursor. Is there another way to do this?

I think you can use the ‘rayCast’ function, which does provide the hitposition, by providing the camera as the objFrom parameter. I have no idea why the camera.getscreenray doesnt provide the hit position though… i think it should provide the same data that the raycast function does

Would something like this be any help:

mouseOverAnySensor = cont.sensors[“sensorName”]
mouseOverAnySensor.hitPosition

not 100% sure if I recall it right. but as long as the cursor is over some element surface it can return the vector position it’s at.
Although one problem I had with this was when dragging an object the cursor kept reading the position of the surface from the dragging object thus moving the object towards the camera (you can make the dragging object a ghost or something though to make it ignore all else except the surface).

check Prof. Monster’s Drag&Drop Support. It should help :smiley:

You’ll proably also find this tutorial by Goran to be very helpful.

Everyone, thanks for the info. Goran’s tutorial had what I needed in it.

anurag.k, That’s a good try but it would would just find the center of the screen each time instead of where the mouse was since that function would just go back to the camera’s origin.

Monster, I couldn’t quite use your drag + drop library since I need to be able to drag multiple selected objects at the same time and the dragged objects need to snap to 1 BU increments and my display is an ortho projection. Your notes say that your lib only works in perspective.

It looks like the solutions from Mperonen and Mobious->Goran will get me what I need.