Difference between Linecast and Raycast


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


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.

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)

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.