RayCast2 - Cast rays on a 2D Surface!

RayCast2 is an easy to use, accurate and documented Raycasting module, specifically for Guis and 2D Game development. Its similar to how Raycasting works when using parts in Roblox studio. If you are into 2D game development, this module is for you!

Raycasting is a very beneficial concept. Read more about it on the wiki:

The module is used to detect hit points of the ray and can be used in ray tracing:

Why use RayCast2?

2D Game development engine features are not present in a wide variety in Roblox studio, therefore I created this module to ease development for some of you. This module is an accurate and easy to use ray casting module for guis.

"Oh thats easy to make! Why use it then?"

RayCast2 not only is accurate but also works with Rotated gui elements! You might question its accuracy. Take a look at this:

"Ha! What if there was another gui in front of that?!"

If there was. It’ll work as expected! It’ll strike the gui that comes in its way first!

"Hmm, that ray points in only 1 direction, what if I wanted to make diagonal rays??"

This module has got your back, it can cast rays in any direction! Look at this slanted ray!

There are several features and examples listed in the documentation and the post!

Raycasting on a 2D surface can be used in many areas of a 2D game. For example:

  • Identifying obstacles
  • Making AI
  • Turrets
  • Projectiles
  • Hit detection
  • Movement
  • Other such mechanics


The module is free to use, get the module here:


This module is well documented. The documentation covers the api, debugging and troubleshooting. If you have any trouble with understanding how to use this module, feel free to send a PM or reply to this post, and I’ll help you as soon as possible.


The source code for this module can be found here:

Planned Updates

  • RayCast2:CastWithIgnoreList()
  • Faster algorithm to find the closest intersection of ray and guis

I am always excited to help the community out wherever I can. I am glad if this helped you in development. More from me soon! That’s all for today, see ya some time later folks! :+1:

Thanks! :cookie:


Nicely done! Thank you for sharing it with the community, very well made, although I won’t personally use this, I can see how this could be tremendously useful!

1 Like

Was expecting to see something like this appear in the dev forum community.

I created an Example Placefile to showcase a simple simulation with 4 rays pointing towards the roblox logo from different directions and forming circles on the point of intersection:

RayCast2.rbxl (37.5 KB)

1 Like


  • Major bug fixes.
  • Cleaned unorganised code.
  • Fixed rotations of visible rays.

:CastWithIgnoreList() releasing tomorrow!

(Been really busy with stuff, update will be a delayed a few days. Sorry)

1 Like

Wouldn’t it be better to have a single Raycast method with something like RayCast Params, to make learning this as easy as possible?

That’s a good idea, in fact it’ll make it easier for people to use, thanks for the suggestion! I’ll look into it before releasing the update!

can the ray be reflected like the roblox 3d raycast? you know what i mean

As of now, it can’t reflect rays, though if you know what you are doing, you can easily reflect rays by casting a ray on the hit to some other direction by calculating the angle, will add this in the future. Thanks!

ohk i got it plus im learning rays in my science classes now so probably i can do that easily I HOPE I CAN

1 Like

This is pretty amazing; I was wondering, does this support circles?
And, maybe you could allow players to input functions for UI elements so it’s not limited to squares; you could also consider allowing users to input functions meant for different types of graphs (e.g polar, allowing for more complex shapes to be used as well).

I’ll add that in the coming update, circles are pretty easy to make compatible with this module!

For sure in the future!

The github doesn’t work with Rojo.
Because the scripts are layed out like this:
Rather than like this:
It won’t work as the main script expects the modules to be direct children. You should probably fix that.

I’ll fix that, the problem was, the other modules had to be parented to RayCast.lua, which isn’t possible on github, I’ll probably change the layout to make it work for rojo, thanks! Will be fixed by today.

Edit: Has been fixed!

1 Like

Can this still be used as a sort of 3D raycasting or is it only strictly 2d?

Strictly 2D! You can use Roblox’s raycast api for 3D objects.

Im having a problem,whenever i raycast it the results are strange, its supposed to ray into all of the corners and corners of the box but its all moved to left