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!