(What happens:)
The laser beam is appearing in front of the ship while i’m moving in that direction, but when I am not moving the laser comes from exactly where it should.
(What should happen. My velocity is at 0 for this test.)
The effect is amplified with how fast i’m moving using BodyMovers.
The code I use to generate the laser:
local origin = firePoint.Position
local direction = target.Value.Position - origin
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
if raycastResult then
local hitpart = raycastResult.Instance
if hitpart == nil then
return
end
if hitpart:IsDescendantOf(script.Parent.Parent.Parent) then
return
end
local damageToDeal = (config.DamagePerSecond/60)*config.ShotLength
energy.Value = energy.Value - config.EnergyPerSecond/60
if hitpart.Parent:FindFirstChild("Core") then
local core = hitpart.Parent.Core
damage(core, damageToDeal)
elseif hitpart.Parent.Parent:FindFirstChild("Core") then
local core = hitpart.Parent.Parent.Core
damage(core, damageToDeal)
elseif hitpart.Parent.Parent.Parent:FindFirstChild("Core") then
local core = hitpart.Parent.Parent.Parent.Core
damage(core, damageToDeal)
end
local BeamPart = Instance.new("Part")
BeamPart.Name = "BeamPart"
BeamPart.Color = config.Color
BeamPart.Material = Enum.Material.Neon
BeamPart.Parent = workspace.FX
--local BeamMesh = Instance.new("SpecialMesh")
--BeamMesh.MeshType = "Sphere"
--BeamMesh.Parent = BeamPart
local v = (origin - raycastResult.Position)
BeamPart.CFrame = CFrame.new(raycastResult.Position + 0.5*v, origin)
BeamPart.Size = Vector3.new(config.BeamXY[1], config.BeamXY[2] ,v.Magnitude)
wait(1/60)
BeamPart:Destroy()
How do I get an accurate position of a BasePart thats moving via a BodyMover?