So im trying to make a laser beam that progressively gets longer only forward. I haven’t found a good method to only make it extend in one direction. part:Resize() makes it stop when it hits something which I don’t want to happen and just adjusting the CFrame/Lerping the position and size makes it lag on the server and I want the beam to be serversided.
Try this.
local laser = game.Workspace.laser
for i = 1, 10, 1 do
i = i + 1
laser.CFrame = CFrame.new(i, 2, 2)
end
If it doesn’t work, reply me.
You can change the 10 to however long you want.
Just a suggestion btw, whenever you show code examples to someone, it’s good if you explain what the main lines do. Because the person may be new
Ah okay, thanks!
30 letters ahahahahah.
The size of a Part is always defined in terms of it’s X, Y and Z extents in it’s own local coordinate system. The Z
direction is forwards/backwards, so increasing the Z component of a Part’s Size makes it grown in the “forwards direction”.
You might also want to keep one end of the beam in the same position even when it changes size. We need to move it “half the change in size” forwards.
In code, this might look like so:
function growLaserBeam(beamPart, growAmount)
beamPart.Size += Vector3.new(0, 0, growAmount)
beamPart.CFrame += beamPart.CFrame.LookVector * growAmount * 0.5
end
local beamPart = --the part that represents your laser beam
while true do
growLaserBeam(beamPart, 0.1)
wait()
end
5 Likes