So in short I’m trying to validate if a raycast is legit (not going through walls) and I currently created this script:
function RaycastIsVerified(RaycastParameters, RaycastResult, Player, Length)
local Character = Player.Character
local StartPosition = Character:FindFirstChild("Head").Position
local EndPosition = RaycastResult.Position
end
These are the parameters in the script above:
--RaycastParameters:
local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist
RaycastParameters.FilterDescendantsInstances = GatherIgnoredRaycastParts(Player.Character)
RaycastParameters.IgnoreWater = false
--RaycastResult:
local RaycastResult = WorkspaceService:Raycast(CameraInfo.Origin, CameraInfo.Direction*Length, RaycastParameters)
--Player is just the player that fired the remote that eventually created the ray and length is always 100.
I have no idea what to do in the RaycastIsVerified function.
Also for more info, RaycastResult is a 3D world position that’s not verified. This means the player can use shiftlock and click through walls. I want to make an ‘extra safety step’ I suppose to stop exploiters from removing walls and being able to shoot/click through them.
Is it something you are trying to verify for debugging? Or does it need to verify ingame.
For debugging you can instead just create a part at the results position to get a visual indicator.
If it needs to verify in game, you can just cast a new ray inside the raycast is verified function from the parameters youbpassed in and make it return whether that raycast hit something or not.
I figured that out, sorry for not disclosing this earlier I just thought it didn’t matter, but the RaycastResult parameter is a ray formed from a 2D click (from clicking on their screen, etc) to a 3D world position.
I wanted to create the RaycastIsVerified function so I could make sure that the player isn’t using shiftlock to click through walls/exploiting by removing walls.
I don’t know anything math related so I don’t know how to do it.
Raycast results from Camera:
local RaycastResult = WorkspaceService:Raycast(CameraInfo.Origin, CameraInfo.Direction*Length, RaycastParameters)
Verify raycast results using Player’s head:
local VerifyRaycastResult = WorkspaceService:Raycast(Character.Head.Position, --don't know how to get raycast direction or cframe or whatever, RaycastParameters)