Raycast visual module

Update 1.2: Raycast visual module 1.1 issues fixed, update it if you got this version.

About

Hello! So all of you may used Ray.new or workspace:Raycast function to create raycasts, right? The worst part is to understand if raycast is at right direction and etc. To check it most of time need to visual it which is time consuming and so, I decided to create a module that creats and visualisaing raycasts. This is my very first module like that so don’t have high expectations.

Why should I use it?

It’s can create rays and raycasts only in 1 line, so you don’t need whole block of code to create it. It also visuals rays and raycasts if you need!

How do I get it in my project?

Easy. You need install model with that module: Raycast Visual Module - Roblox . Then you must go to roblox studio and import model. Place it anywhere you want!

How do I use it?

Easy. Here’s an example of how to use it:
So first of we need get module.

local RCVisualModule = require(game.ReplicatedStorage.RaycastVisualModule)

In example I want red part fire raycast that will touch green wall, but ignore orange part infront of her.

I can choose 3 versions of raycats. FindPartOnRay, FindPartOnRayWithWhitelist or Raycast. For this task I need FindPartOnRayWithWhitelist or Raycast. Let’s see FindPartOnRayWithWhitelist

It returns 3 values, ray himself, hit and hit position.

local RCVisualModule = require(game.ReplicatedStorage.RaycastVisualModule)

local RedPart = workspace.RedPart
local OrangePart = workspace.OrangePart

local RayHit, HitPosition, Ray = RCVisualModule:FindPartOnRayWithWhitelist()

I have used function, but it won’t fire raycast without info we need: Origin - From what position should we fire ray, Direction - At what direction we must fire ray, IgnoreTable - Table that contains all parts we need to ignore. TerrainCellsAreCubes - Bool value… Actually I don’t know what it is, Ignore water - Boolean value. If you want ignore all water (created by terrain thingy) set it to true, Visual - Boolean value. Set to true if you want visual ray, VisualDebris - Time after what visual part will disapear. Leave it empty if you don’t want it to disapear.
Thats all what we need. Let’s start!

local RCVisualModule = require(game.ReplicatedStorage.RaycastVisualModule)

local RedPart = workspace.RedPart
local OrangePart = workspace.OrangePart

local RayHit, HitPosition, Ray = RCVisualModule:FindPartOnRayWithWhitelist(RedPart.CFrame.p,RedPart.CFrame.UpVector*-20,{RedPart,OrangePart},false,true,false)

We have created raycast, cool! But we want make sure it touched green wall. Sure we can just print RayHit name but we don’t like easy ways. So to do it we must turn last argument into true.

local RCVisualModule = require(game.ReplicatedStorage.RaycastVisualModule)

local RedPart = workspace.RedPart
local OrangePart = workspace.OrangePart

local RayHit, HitPosition, Ray = RCVisualModule:FindPartOnRayWithWhitelist(RedPart.CFrame.p,RedPart.CFrame.UpVector*-20,{RedPart,OrangePart},false,true,true)

And here it is!
изображение

As you see this yellow bar starting from red part is a visual part! But what if I already using this module and you want see ALL raycasts fired by this module? You need rewrite all scripts using it. Let’s take a look into module script

local module = {}
local inStudio = true

Pay attention to second line. You want set value of it to true if you want see ALL rays visauls. It will visual all of them no matter what… Well sure if you in studio.

That’s all! Info about other functions you can find inside module. I have tried write understanable description for all of them. You can freely edit this module if you need to. Hope it helped you!

3 Likes

I hate to be that guy. But can’t you just do:

	ShootPart.CFrame = CFrame.new(Origin.CFrame.Position, ShootCast.Position) * CFrame.new(0,0,-Distance /2)
		ShootPart.Size = Vector3.new(0.25,0.25,Distance)

This feels a lot more complicated rather than to just do it above. Considering there’s also little to no customization with the ray part.

2 Likes

That’s actually how module works. But you still need set up shoot part as: create it, disable collide, set size, set cframe, find distance and etc when you can do it in single line.

I mean like, you can’t change color. Also squeezing everything into 1 big line doesn’t help. Instead makes it look way more complicated then it really is. You’d be better off doing it like the way I said above. Since you’ll have more customization

You can customize visual part by editing module.
oh wait
ye, customizing visual part will be complicated since all 3 functions using it in themselfs instead of creating function that creating visual part.
About squeezing im agree, but it’s the only way im know sadly.

Also, looking into the source code, this module uses deprecated methods. workspace:FindPartOnRay, etc. workspace:RayCast can do all of these. Also, what if I want 1 ray to be blue but the other to be yellow, what would I do then? Also, instead of a million arguments you can just do:
Origin, Direction, RaycastParams. Instead of this:

Origin: Vector3, Direction: Vector3, RaycastParamsTable: table, RaycastParamsType: Enum.RaycastFilterType, Visual: BoolValue, VisualDebris: NumberValue

It would’ve been more useful if you made a tutorial on how to visualize rays.

I made workspace:FindPartOnRay and workspace:FindPartOnRayWithIgnoreList since some of people still using it like me. About million agruments you are right, I couldn’t find any other way of inserting visual part into ignore table for raycast. Im still gonna be trying updating this module so it could be much useful instead of current version.

Also just remembered that module returns visual part as 4 value in FindPartOnRay and etc, and as second in Raycast so you still can customize it.