This is a video of my current progress So I redid the code using the Raycasting method and it works way better! The only problem is sometimes the beam glitches to random areas. I don't know why it does this, but I think it has something to do with the Ray.
Here's the new method:
First I created a visual part ( I use this part to represent effects that I hope to add latter) that spawns a couple studs in front of the character. After this I create the beam part, that spawns right inside the Visual part.
Mouse.Button1Down:Connect(function() mousedown = true CVB:FireServer() -- Creates the Visual Part and Beam Mouse.move:Connect(function() if not mousedown and not player and not Humanoid and not Humanoid.Health > 0 and not Torso and not debounce then return end local MouseHit = Mouse.Hit local HumanoidRoot = Character:WaitForChild("HumanoidRootPart") local Distance = (Torso.Position-MouseHit.Position).magnitude if Distance > 500 then Distance = DistanceMax end FlameStart:FireServer(mousedown,Torso,MouseHit,Distance) -- Creates the RayCast and updates the beam's CFrame end) end)
I have another function create the Visual part and beam Part. This code is meant to update the beam's CFrame
FlameStart.OnServerEvent:connect(function(...) local tuple = {...} local player = tuple[1] local mousehit = tuple[2] local Torso = tuple[3] local MouseHit = tuple[4] local Distance = tuple[5] if Torso and MouseHit and player.Character and Distance then --Ray Cast-- local ray = Ray.new(Torso.CFrame.Position, (MouseHit.Position - Torso.CFrame.Position).Unit * 500) local part,position = workspace:FindPartOnRay(ray,player.Character,false,true) --UpdateBeam's CFrame -- beam.Size = Vector3.new(0.5,0.5,Distance) beam.CFrame = CFrame.new(Torso.CFrame.Position ,position) * CFrame.new(0,0,-Distance/2) end end end
The beam gets created and it's direction is adjusted when I move my mouse, but the length and positioning sometimes is incorrect.
Any advice would be appreciated, i've been stuck on this for weeks... lol
If you need help visualizing this should help https://www.youtube.com/watch?v=eqqBj3981SU (Like the beams in Lego Marvel SuperHeroes)
Thanks Again,