Ray.new() and WorldRoot:Raycast()

Good morning guys, so my question is when making guns, i have seen tutorials doing guns and some of them used one of this two,Ray.new() and WorldRoot:Raycast() and this made me confuse about raycasting, i dont know which one to use, i read the two wiki pages about this two, and i am still confused about this two. So, what’s the difference about this two? Which is better to use generally speaking? either guns, eye casters, superman eyes, star wars,etc. Thank you very much in advance, have a great day!

2 Likes

For the most part they do the same thing but WorldRoot:Raycast is newer and will likely be updated with new functionality in the future, and the older raycasting functions like Ray.new() FindPartOnRay, FindPartOnRayWithIgnoreList and FindPartOnRayWithWhitelist are now deprecated:

Correction: The ray object (Ray.new) itself is not deprecated but the functions you would normally use along side it to retrieve information from a raycast are deprecated, so WorldRoot:Raycast should still be used when needing to get an actual result from a raycast operation.

12 Likes

Ohhhhh, yes thanks so much man, you have cleared all my confusions thanks so much!

Hey, sorry I’m late. But is there any reason to use the new WorldRoot:Raycast()? Are there any advantages over the Ray.New().

As far as I am concerned, worldroot:Raycast() doesn’t have any of the functions that Ray.New() has. Such as; ray.Direction - ray.Origin etc. etc.

I recently changed from ray.New() to worldroot:Raycast(), should I go back again (back to Ray.New()?)

Looking forward to your answer.

Afaik Ray.new() got deprecated because of confusing functions - it returned too many things and was generally overcomplicated.

2 Likes

Other than that it’s pretty much the same thing, right? It’s foolish by Roblox to not have the same functions on the “new” raycast, actually, there are none.

I will go back to the “Old” raycast because it’s much more versatile and simpler to use.

Thanks for your answer.

I’ve made a correction to my post, apparently the ray object is not deprecated but FindPartOnRay and such are (not that it makes a huge difference in this case when they were a big part of using Ray.new in the first place). The only real advantage at the moment that I know of is that the new API can account for CollisionGroups. As for ray.Direction and ray.Origin you could probably just use the Direction and Origin that you originally inputted into the WorldRoot:Raycast function, but I do agree that having the ray object’s properties at hand was quite useful and easy. Lastly, while I haven’t tested performance differences, going off the thread I linked, it would seem its mostly negligible atm (raycasting is raycasting). So I think the big reason they introduced the new API is so that it gives them more of an opportunity to add and maintain more raycasting capabilities down the line–even if it means sacrificing simplicity. But to answer your question I think if easy of use is a priority and unless you need a specific functionality either one would be fine for now.

1 Like

Thanks for your extensive answer.

With deprecated, do you mean that I can still use it? If not, what are the alternatives?

Thanks.

Ideally deprecated functions and properties shouldn’t be used (particularly for new work) unless they provide a needed functionally that can’t be had elsewhere. As for the deprecated ray casting functions you can still use them and they aren’t likely going anywhere any time soon, but I’m pretty sure there aren’t any non-deprecated alternatives (other than switching to the new API)

1 Like