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
1
Question by UnbreakableOne · Dec 06, 2014 at 02:26 PM · physic

Difference between Linecast and Raycast

Hi,

I've read the documentation page but could not get the hold of their difference.

Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
9

Answer by DigiScot · Jul 13, 2015 at 09:54 AM

The main difference is a raycast you set the start point then the direction and the distance to check in that direction, a linecast you simply set a start and end and it checks between those 2 points.

So if you know the end destination specifically, use linecast, if you want to check in a specific direction but have no specific end point, use raycast.

Otherwise, cost is pretty much the same, it all depends how far it's checking and what it's checking against.

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 · Jul 13, 2015 at 10:35 AM 0
Share

correct, i'm not sure what Gruffy ment in his post. Also he confuses Raycast and Linecast several times in his post.

They are equally expensive. A Raycast "allows" to cast an infinite ray, but that fact on it's own doesn't make it more expensive. Unity's physics system most likely uses some kind of Octree to deter$$anonymous$$e which colliders it has to check.

avatar image Gruffy · Jul 13, 2015 at 02:28 PM 0
Share

Guys, apologies, my explanation was a bit vague at the time unfortunately, and I had indeed confused the two in my explanation. Don`t know why, I suspect its something to do with me being stupid!

Though I will say what DigiScot had eloquently put, was the intention of my comment. I do have to say, the way I said it was convoluted slightly, perhaps a little confusing and very badly worded lol

Soz guys, hope I`m forgiven for it :) Gruffy

avatar image
1

Answer by Gruffy · Dec 06, 2014 at 02:36 PM

Line cast is effectively cheaper than a ray cast. thought they are very close in speed really. The ray cast simply allows us to also return a distance/ cut off point. A line cast is infinite effectively, if you read between those two sentences, you could see how a ray cast could be made more efficient than the linecast as the need to check an infinite linear distance may not be required. For another nice efficient use of casting thought, check out Physics.Spherecast..... I will leave that with you Click me

Take care bud, hope that helps clarify at least something for you there. (no doubt this statement may raise purist arguments over the whole line vs ray thing lol) Gruffy

Edit: To add its also probably best to include the fact you could also specify things to ignore with ray casts, which I don`t think is possible with a line cast.

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 Bergquist · Oct 21, 2017 at 07:21 PM 0
Share

Linecast() has 5 overloads. Two of which include: public static bool Linecast(Vector3 start, Vector3 end, int layer$$anonymous$$ask); public static bool Linecast(Vector3 start, Vector3 end, out RaycastHit hitInfo, int layer$$anonymous$$ask);

Both of these overload options give you the ability to ignore specified objects by layers with a layer$$anonymous$$ask.

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Springjoint transmit wrong forces 0 Answers

mecanim and rigidbody gravity effect doesnt work 1 Answer

Problem with moving an object and Uni2D Colliders 0 Answers

How to draw line in the game, not editor. 2 Answers

Change the "down" axis for 2D 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