Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how can I make a raycast go from the handle to the position using the characters root?

Asked by 5 years ago

So I want to make this Raycasting script where the player shoots out a beam from the handle to the position of unit * 300 using the lookvector of the players root. I'm not quite sure how i can do this because the raycasting math is a little bit confusing. Can I get any help?

Script

local ray = Ray.new(root.CFrame.p, (char:FindFirstChild("HumanoidRootPart").CFrame.LookVector*10 - root.CFrame.p).unit * 300) local part, position = workspace:FindPartOnRay(ray, char, false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Bright red") beam.FormFactor = "Custom" beam.Material = "Neon" beam.Transparency = 0.25 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (Tool.Handle.CFrame.p - position).magnitude beam.Size = Vector3.new(0.3, 0.3, distance) beam.CFrame = CFrame.new(Tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance /2) game:GetService("Debris"):AddItem(beam, 0.1)

Answer this question