Im trying to recreate this, but I have 0 clue where to start, any help with getting started?
So basically your going to need to raycast a set amount of studs in the direction of the player’s humanoidrootpart, after that the ray returns something called the surface normal which is a vector that is orthogonal to the surface it hit
We can use the normal and the position of the ray to rotate lets say a part directly flat against whatever our raycast hit
For some reason constantly setting the cframe made it very glitchy but I just crate the part and duplicate it, and also you can replicate this pretty easy by just rayasting from the camera
local plr = game.Players.LocalPlayer
local char = plr.Character
local root = char:WaitForChild("HumanoidRootPart")
local bruh = game.ReplicatedStorage.bruh
while true do
local result = workspace:Raycast(root.Position,root.CFrame.LookVector * 5)
if result then
local attachment = Instance.new("Attachment")
attachment.Visible = true
attachment.WorldCFrame = result.Instance.CFrame:ToObjectSpace(CFrame.new(result.Position,result.Position + result.Normal)) * CFrame.Angles(0,math.rad(90),0)
attachment.Parent = result.Instance
local y = bruh:Clone()
y.Parent = workspace
y.CFrame = attachment.WorldCFrame
wait(.005)
y:Destroy()
end
game:GetService("RunService").Heartbeat:Wait()
end
Did some changes and it works with the camera
local plr = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local char = plr.Character
local root = char:WaitForChild("HumanoidRootPart")
local bruh = game.ReplicatedStorage.bruh
while true do
local result = workspace:Raycast(camera.CFrame.Position,camera.CFrame.LookVector * 10)
if result then
local attachment = Instance.new("Attachment")
attachment.WorldCFrame = result.Instance.CFrame:ToObjectSpace(CFrame.new(result.Position,result.Position + result.Normal)) * CFrame.Angles(0,math.rad(90),0)
attachment.Parent = result.Instance
local y = bruh:Clone()
y.Parent = workspace
y.CFrame = attachment.WorldCFrame
wait(.005)
y:Destroy()
end
game:GetService("RunService").Heartbeat:Wait()
end
Also I might add this is probably horrible for performance
It’s very simple, all you need is raycasting, and then when the raycast result is not equal to nil, clone a sphere and position it to the raycastResult.Position. Here is a good raycasting tutorial:
hello ive tried creating a beam as what you wanted:
here the video:
here the Script:
local Part = workspace.laser --the laser part :flush:
local attach1 = Part.Beam.Attachment1
local attach0 = Part.Beam.Attachment0
local run = game:GetService("RunService")
-- Build a "RaycastParams" so that it ignores the beamPoint
local Beampoint = game.ReplicatedStorage.Beampoint:Clone()
Beampoint.Parent = workspace
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {Beampoint} --ignores it
raycastParams.IgnoreWater = true
run.RenderStepped:Connect(function()
local part = Part
local origin = part.Position
local direction = part.CFrame.LookVector*500 --the look vector of the part
local result = workspace:Raycast(origin, direction,raycastParams)
if result then
Beampoint.Transparency = 0 --if there is a result we show the point
attach1.WorldPosition = result.Position
Beampoint.CFrame = CFrame.lookAt(result.Position, result.Position + result.Normal) * CFrame.Angles(0,math.rad(90),0) -- we time by angle 90 because its a cylinder
BeamCircle.Position = result.Position + result.Normal
else
Beampoint.Transparency = 1 --we wont show the point if there is no result
attach1.WorldPosition = Part.CFrame.LookVector * 4000
end
end)
What is the “attachment” classname? could you just send me a place file?
Yea sure here is the file:
Laser.rbxl (24.6 KB)
the Attachment is actually for the beam/laser effect
Tweaked it a little bit and i got this now, I appreciate it a lot!
https://i.gyazo.com/536e46c6fd65a946b5367cf3dcbdad8d.mp4
Slight problem though, I tried to make it work for the server, and now the beam point is goings crazy on the player?
wait(1) local Part = workspace.laser local attach1 = Part.Beam.Attachment1 local attach0 = Part.Beam.Attachment0 local run = game:GetService("RunService") -- Build a "RaycastParams" object and cast the ray local Beampoint = game.ReplicatedStorage.Beampoint:Clone() Beampoint.Parent = workspace local raycastParams = RaycastParams.new() raycastParams.FilterType = Enum.RaycastFilterType.Blacklist raycastParams.FilterDescendantsInstances = {Beampoint} raycastParams.IgnoreWater = true run.Heartbeat:Connect(function(step) local part = Part local origin = part.Position local direction = part.CFrame.LookVector*500 local result = workspace:Raycast(origin, direction,raycastParams) if result then Beampoint.Transparency = 0 attach1.WorldPosition = result.Position Beampoint.CFrame = CFrame.lookAt(result.Position, result.Position + result.Normal) * CFrame.Angles(0,math.rad(90),0) --BeamCircle.Position = result.Position + result.Normal else Beampoint.Transparency = 1 attach1.WorldPosition = Part.CFrame.LookVector * 4000 end end)
my bad i forgot to anchor the Beam point and set its can collide to false. now its working perfectly fine on the server