Guys, I have been searching on youtube for a tutorial on how to raycast. Most tutorials are old and a lot of stuff is deprecated. The newer videos just dont explain it properly and are to advanced. I am a big noob at scripting. I really need a very detailed explanation and tutorial about how to raycast.
5 Likes
-
Get a starting position
-
Get a direction vector (No, not position. Direction. Like,
(goal.Position - start.Position
OR
-start.Position + goal.Position))
(Use ‘Vector Triangle Method’ to visualize a direction vector) -
Get a RaycastParams object (Optional, raycast still works without this)
local rayParam = RaycastParams.new()
rayParam.FilterDescendantInstances = {workspace.IgnoreFolder}
rayParam.FilterType = Enum.RaycastFilterType.Blacklist
rayParam.___ -- autocomplete will tell you what you can add more
- Raycast (don’t leave out the local ray = ___, you’ll use them later)
local ray = workspace:Raycast(startPosition, directionVector, rayParam)
- Hit detection
if ray then
-- Some properties you can get
ray.Instance -- The part hit (can return Terrain)
ray.Position -- The position the hit occured
ray.Material -- The material of the Instance (works for terrain too)
ray.Normal -- LookVector, except it's the direction from the face of a part
end
23 Likes