I’m making an ability where a laser pierces everything in a radius of X studs. However, laser isn’t displaying properly for some reason, despite coordinates being correct (desired coordinates can be seen as red parts appearing on the video).
--Tool.Instance.Handle.Aim is the position from where laser should be fired out
--IndeedItIs.Coordinates is a position of player's cursor
local Coordinates = Tool.Instance.Handle.Aim.Position + (IndeedItIs.Coordinates - Tool.Instance.Handle.Aim.Position).Unit * 50
print(IndeedItIs.Coordinates, Tool.Instance.Handle.Aim.Position, Coordinates)
local d = Instance.new("Part")
d.Color = Color3.new(1, 0, 0)
d.Anchored = true
d.CanCollide = false
d.CanQuery = false
d.Transparency = 0.6
d.Position = Coordinates
d.Parent = workspace
local Shot = game.ReplicatedStorage.Assets.Weapons.Juggernaut["Retributor v2.0.1"].RetributeCritical:Clone()
Shot.Size = Vector3.new(50, 2, 2)
Shot.Position = Tool.Instance.Handle.Aim.Position:Lerp(Coordinates, 1)
Shot.CFrame = CFrame.lookAt(Tool.Instance.Handle.Aim.Position, Coordinates)
Shot.Rotation -= Vector3.new(0, 90, 0)
Shot.Parent = workspace
I believe the part pivot is at Tool.Instance.Handle.Aim.Position so it starts there and doesnt end up stretching to the end position, Coordinates visually. you can pivot it back by half of its length, heres the updated code:
local Start = Tool.Instance.Handle.Aim.Position
local Coordinates = Start + (IndeedItIs.Coordinates - Start).Unit * 50
local Distance = (Start - Coordinates).Magnitude -- distance between start and end
local d = Instance.new("Part") -- create visualizer
d.Color = Color3.new(1, 0, 0)
d.Anchored = true
d.CanCollide = false
d.CanQuery = false
d.Transparency = 0.6
d.Position = Coordinates
d.Parent = workspace
local Shot = game.ReplicatedStorage.Assets.Weapons.Juggernaut["Retributor v2.0.1"].RetributeCritical:Clone()
Shot.Size = Vector3.new(50, 2, 2)
Shot.Position = Tool.Instance.Handle.Aim.Position:Lerp(Coordinates, 1)
Shot.CFrame = CFrame.lookAt(Start, Coordinates) * CFrame.new(-Distance/2, 0, 0)
Shot.Rotation -= Vector3.new(0, 90, 0)
Shot.Parent = workspace