Jump to content

Resolving On-Screen Pointer to 3D Coordinates


Recommended Posts

Hello Folks.

I'm completely new here and new to the world of modding (though I have been playing KSP for a few years).  I am developing my first mod, which I expect will be ready just in time for 1.1 to break it.  But I am already looking towards future enhancements that I may want to make.

One thing I would like to do is, while viewing the KSC in the SpaceCenter scene, I would like to determine the latitude, longitude and altitude of whatever is currently under the mouse pointer.  I tried looking online and through the object browser, but I could not find anything that looked like it would give me this sort of information.  I know it must be possible (to some degree) because Squad is able to tell which building you click on in that screen.

Any advice would be greatly appreciated.

Link to comment
Share on other sites

hum.  I think the OP asked for the reverse :P

RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        
if (Physics.Raycast(ray, out hit)) {
     Vector3 pos = hit.transform.position;

There are more than one camera in KSP. Not sure if Camera.main is always the right choice (I think there is one in ScaledScpace  too )

Link to comment
Share on other sites

Sarbian,  thank you. This does look more like what I was searching for. 

Wow! I ask a question at noon on a workday and I get  answers with code examples before I leave for home! The KSP community is great!!! 

Edited by Antipodes
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...