Hello, I am fairly new to lua and roblox scripting, How would I go about casting a ray downward at a 45 degree angle from the torso/humanoidrootpart? I have browsed a few other forum posts and none of the way's have worked for me. Here's what I was able to do but downwards was not successful neither was a 45 degree angle. Any help will be appreciated.
local player = game.Players.LocalPlayer local char = player.Character local torso = char.HumanoidRootPart local origin = torso.Position local direction = torso.CFrame.LookVector * 100 local raycastParams = RaycastParams.new() raycastParams.FilterDescendantsInstances = {char} raycastParams.FilterType = Enum.RaycastFilterType.Blacklist local raycastResult = workspace:Raycast(origin, CFrame.Angles(0,math.rad(90),0).lookVector * direction, raycastParams) if raycastResult then print(raycastResult.Instance) else print("hit nothing") end
If I have worded this wrong this is what I want to happen
local distance = 10 local torso = char.HumanoidRootPart local Diagonal_Front_Down = torso.Position + torso.CFrame.LookVector * distance - Vector3.new(0,distance,0) local Origin = -- set your stating point here (Vector3) local EndPoint = Diagonal_Front_Down local raycastParams = RaycastParams.new() raycastParams.FilterDescendantsInstances = {char} raycastParams.FilterType = Enum.RaycastFilterType.Blacklist local raycastResult = workspace:Raycast(Origin, EndPoint - Origin, raycastParams) if raycastResult then print( raycastResult.Position, raycastResult.Instance, raycastResult.Material, raycastResult.Normal ) -- mor info in https://developer.roblox.com/en-us/api-reference/function/WorldRoot/Raycast end