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
2
Question by Jordii · Jan 25, 2011 at 11:05 PM · raycastdistanceplanerayinfinite

Math - calculate position in world space from ray on infinite plane

Hey everyone,

I'm currently using the Unity Plane object to create an infinite plane, and to cast several rays against it. Like so:

Example

Plane.Raycast returns

1) whether it has hit the plane or not, and

2) the distance, in case it has a hit

So I cast a ray from my camera, and it hits my plane. However, with just the distance information I cannot calculate where in 3D space each ray hits.

What mathematical calculations can I use in order to calculate the 3D intersectionpoints of each ray?

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 Bunny83 · Jan 25, 2011 at 11:16 PM 0
Share

Sorry just read the Plane.Raycast :D. wait, i'll add an example

2 Replies

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

Answer by Bunny83 · Jan 25, 2011 at 11:13 PM

Basically if you cast a ray you normally have a starting point and a direction vector. if you have the distance you hit something just add the normalized direction vector multiplied by the distance to your starting point. That's it. But the Ray class in Unity have a special function that will do that for you: Ray.GetPoint()

{
   Ray myRay = new Ray(startpoint, direction); // or use any other ray
   float dist;
   if (myPlane.Raycast(myRay,out dist))
   {
      Vector3 hitPoint = myRay.GetPoint(dist);
   }
Comment
Add comment · Show 4 · 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 Jordii · Jan 25, 2011 at 11:20 PM 0
Share

That doesn't work, that is RaycastHit which is information extracted from a normal Raycast. I cannot use normal Raycasts since they only can be done on meshcolliders. $$anonymous$$y infinite plane is no mesh, it's a theoretical plane. Check Plane: http://unity3d.com/support/documentation/ScriptReference/Plane.html

avatar image Bunny83 · Jan 25, 2011 at 11:27 PM 0
Share

yeah, sorry, I changed the answer already ;)

avatar image Jordii · Jan 25, 2011 at 11:30 PM 0
Share

Ah your answer has been editted :D So my last reply doesn't fit the bill. I will try this tomorrow Bunny. Using the Ray object was new to me, hope it'll work :) Thanks for adding the math too, I want to understand that part too!

avatar image Jordii · Jan 26, 2011 at 09:41 PM 0
Share

Bunny thanks very much, just checked it, and it worked :)

avatar image
2
Best Answer

Answer by Peter G · Jan 25, 2011 at 11:26 PM

Use Plane.Raycast() then ray.GetPoint()

var ray : Ray; var dist : float;

if( Plane.Raycast(ray, out dist) ) { var hitPoint : Vector3 = ray.GetPoint(dist); }

Comment
Add comment · Show 2 · 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 Bunny83 · Jan 25, 2011 at 11:34 PM 0
Share

Great now we have both C# and Unityscript ;)

avatar image Jordii · Jan 26, 2011 at 09:42 PM 0
Share

Thank you sir, although Bunny pointed me in the right direction, your help is much appreciated

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

No one has followed this question yet.

Related Questions

Raycast refuses to cast down 1 Answer

Help with some C# 1 Answer

How can i tell the distance from a raycast? 1 Answer

Bounds IntersectRay distance isnt correct 1 Answer

Unreliability of Physics.Raycast.Distance for player movement? 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