Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jul 03, 2013 at 09:00 AM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by yyykobe · Jul 03, 2013 at 08:30 AM · positionmousescreenclickcoordinate

click on screen to get the coordinate on the ground(x,z plane)

Hello, I am making 3D map. there is a ground on the x,z plane. I want to click on the ground, and to know which point on the ground i am clicking on. I am looking for the clicking point's coordinate in the worldspace(x,0,z). I am stuck in this problem for a week, I need your help. Thanks in advance. I

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by markpdolby · Jul 03, 2013 at 08:57 AM

 void Update(){
    Ray ray =Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;
    if(Physics.Raycast(ray, out hit, 100, LayerMask.NameToLayer("Terrain")))
     {
        Debug.Log(hit.point);
     }
 }

Use a ray cast from the mouse position onto the ground. the two things you might need to change are the 100 which is maximum distance the ray will travel and the layer name to whatever layer your ground is on. See the docs for more detail: http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CarterG81 · Feb 23, 2017 at 04:59 PM 0
Share

Layer$$anonymous$$ask.NameToLayer("") didn't work for me.

I had to use Layer$$anonymous$$ask.Get$$anonymous$$ask("")

  //get the mask to raycast against either the player or ground layer
  int l$$anonymous$$ask  = Layer$$anonymous$$ask.Get$$anonymous$$ask("Player", "Ground");
  //player only
  //int l$$anonymous$$ask = Layer$$anonymous$$ask.Get$$anonymous$$ask("Player");

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

mouse clicking on the plane and drag to other position 1 Answer

Firing projectile towards mouse position from player... 0 Answers

Player to look at 0 Answers

how to make the object position related to the screen 2 Answers

Spawn Objects Where i click 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges