How can I make a raycast in front of the player and look down

Hi, I need help! I need to move the raycast so that it is in front of the player and looks down.

game.UserInputService.InputBegan:Connect(function(k,g)
if k.KeyCode == Enum.KeyCode.E then
local part = Instance.new(“Part”);
part.Anchored = true;
part.CanCollide = false;
part.Parent = workspace;
local plr = game:GetService(“Players”).LocalPlayer;
local char = plr.Character or plr.CharacterAdded:Wait();
local humrp = char:FindFirstChild(“HumanoidRootPart”);
local dir = part.CFrame.UpVector;
local params = RaycastParams.new();
params.FilterType = Enum.RaycastFilterType.Blacklist;
params.FilterDescendantsInstances = {char};
local ray = workspace:Raycast(humrp.Position,humrp.CFrame.UpVector * -20,params);
if ray then
part.Position = ray.Position;
end
end
end)

Full script

local ray = workspace:Raycast(humrp.Position+(humrp.CFrame.LookVector*2),part.CFrame.UpVector * -20,params)

You can change the 2 in LookVector * 2 to a higher number depending on how far in front of the character you want to set it.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.