Im trying to make a beam raycast from the zombies torso forward. The problem is it is bent and not perpendicular to the torso and when the zombie moves towards me it generates a new beam on a similar rotation. I have figured out the all the beams are pointing towards the centre of the map(0,0,0)
function raycast()
local ray = Ray.new(
(script.Parent.Torso.CFrame).p ,
(script.Parent.Torso.CFrame.lookVector * 5)
)
local part, position = workspace:FindPartOnRay(ray, nil, 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 = 5
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(script.Parent.Torso.Position, script.Parent.Torso.CFrame.lookVector ) * CFrame.new(0, 0, 2.5)
end
while true do
wait(1)
raycast()
end
