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 /
avatar image
0
Question by AlucardJay · Sep 07, 2012 at 08:53 PM · cameravector3distance

find a world-space coordinate from ScreenPointToRay(Input.mousePosition) raycast

How can I find the World-Space coordinate from a raycast with a set distance, without hitting a collider?

Or : is there a proper way of finding a world space coordinate from a 2D input and a set distance from the camera? Example :

Player touches the screen or uses a mouse, either way the input is a screen coordinate.

Ray is cast at a distance of 10.0 :

 if ( Physics.Raycast( Camera.main.ScreenPointToRay(Input.mousePosition), 10.0) ) {

even if there is no colliders, how can I get a return for the point that is at the end of the raycast? Thanks =]

Comment
Add comment · Show 1
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 AlucardJay · Sep 07, 2012 at 09:08 PM 0
Share

I really hope there is a simple solution, without using the camera's transform and rotation, ins$$anonymous$$d with both Input.mousePosition and Input.GetTouch(i).position

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ThermalFusion · Sep 07, 2012 at 09:26 PM

 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 Vector3 point = ray.origin + (ray.direction * distance);
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 AlucardJay · Sep 08, 2012 at 05:47 PM 0
Share

Thankyou, this is exactly the kind of thing I was looking for, but didn't know Ray even existed. This has been most helpful (upvote to you!) : http://docs.unity3d.com/Documentation/ScriptReference/Ray.html

Here is a JS version for anyone else who may read this :

  #pragma strict

  public var distance : float = 4.5;

  function Update() {
       CastRayToWorld();
  }

  function CastRayToWorld() {
       var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);    
       var point : Vector3 = ray.origin + (ray.direction * distance);    
       Debug.Log( "World point " + point );
  }
avatar image
0

Answer by Hesher · Jun 24, 2014 at 09:28 AM

"var point : Vector3 = ray.origin + (ray.direction * distance); "

is equal to:

"var point : Vector3 = ray.GetPoint(distance);"

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Vector3.Distance between camera and raycasthit 2 Answers

Keep camera at certain distance from character when rotating 3 Answers

Set Distance to object 1 Answer

Vector3(x,y,variable)? 0 Answers

Find distance between two points on two objects 0 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