I was wondering how you would draw a line between two parts, similar to the one on pet sim x, the line between your pet and the object it is going to collect. I tried using beams but I can’t get a way to make them flat on the ground. Does anybody know how to create a line similar to this.
I haven’t really tested it yet but try this.
local part1 = workspace.Part1
local part2 = workspace.Part2
local line = Instance.new("Part")
line.Anchored = true
line.Parent = workspace
while true do
line.CFrame = CFrame.lookAt(part1, part2)
line.Size = Vector3.new(0.1, 0.1, Vector3.new(line.Position.X - part2.Position.X, line.Position.Y - part2.Position.Y, line.Position.Z - part2.Position.Z ).Magnitude)
wait()
end
This creates just a part that connect the two pieces, i am trying to create a dynamic dotted line that gets smaller the closer the two parts are, also want the dots to move along the line, like it does on a regular beam. The only problem i am getting is making a beam straight, i can change the orientation of the attachments, but I wouldnt know how to calculate the orientation needed for the two attachments to have the orientation that makes the beam flat
Can you show me how your beam looks like right now?
all I have done to this beam is change the orientation of the attachments, i want to know how I would calculate the correct orientation needed so wherever I stand the attachments will be at the correct orientation so the beam is straight
you’d probably have to change the orientation on both to like (90,0,0)
I’ve tried that, it only works if the player is head on to the part.
perhaps set it to the orientation of the parent of the attachment?
You can try and disable FaceCamera (last property in the img)
facecamera is disabled, i just need some sort of way to get the orientation of the attachments to face each other.
Maybe use LookVector? ----------
I’m not sure how to get that working with attachments as their cframe is only local and when i try to change their world properties they don’t seem touse the lookat as intended
Beams are the correct answer for this. You just need to make sure that both attachments are of the same rotation (the axis that affects the twisting of the beam), and then position them on the ground.
Alternatively, you could use physical parts that connect between the locations and have something like a texture animate across. There’s quite a few options you can go for. I would, however, recommend implementing pathfinding into the guidance system. There’s almost no games on Robox that do this and it makes no sense to me why they don’t. But clearly that’s optional.
You can use the Instance.new
function to create a Part or LineHandleAdornment
instance and set its properties accordingly.
-- Get the two parts you want to draw a line between
local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2
-- Create a new LineHandleAdornment instance
local line = Instance.new("LineHandleAdornment")
line.Parent = part1
-- Set the properties of the line
line.Length = (part1.Position - part2.Position).Magnitude
line.Thickness = 2
line.Transparency = 0.5
line.Color3 = Color3.new(1, 1, 1)
-- Position the line between the two parts
line.Adornee = part2
line.AlwaysOnTop = true
line.ZIndex = 1
line.Visible = true
Here is an example place I made, that might help
BeamPath.rbxl (43.9 KB)
local busy = false
function HandleTouch(block,part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player and player == game.Players.LocalPlayer and not busy then
busy = true
if player.Character:FindFirstChild("Beam") then --remove the beam
local folder = player.Character.Beam
if folder and folder:FindFirstChild("SrcRef") and folder:FindFirstChild("DstRef") then
local src = folder.SrcRef.Value
local dst = folder.DstRef.Value
if dst and dst.Parent == block then
if src then src:Destroy() end
dst:Destroy()
folder:Destroy()
end
end
else --create the beam
local target = block
while target == block do
target = workspace:WaitForChild("Targets"):WaitForChild("Part"..math.random(1,4))
wait()
end
local folder = Instance.new("Folder")
folder.Name = "Beam"
local srcAttachment = Instance.new("Attachment")
srcAttachment.Parent = player.Character.HumanoidRootPart
local dstAttachment = Instance.new("Attachment")
dstAttachment.Parent = target
local srcRef = Instance.new("ObjectValue")
srcRef.Name = "SrcRef"
srcRef.Value = srcAttachment
srcRef.Parent = folder
local dstRef = Instance.new("ObjectValue")
dstRef.Name = "DstRef"
dstRef.Value = dstAttachment
dstRef.Parent = folder
local beam = Instance.new("Beam")
--beam.FaceCamera = true
beam.Transparency = NumberSequence.new(0)
beam.TextureSpeed = .5
beam.TextureLength = 5
beam.TextureMode = Enum.TextureMode.Stretch
beam.Width0 = 3
beam.Width1 = 3
beam.CurveSize0 = 0
beam.CurveSize1 = 0
beam.Segments = 1
beam.Texture = "http://www.roblox.com/asset/?id=1145531104"
beam.Attachment0 = srcAttachment
beam.Attachment1 = dstAttachment
beam.Parent = folder
local origDist = Instance.new("NumberValue")
origDist.Name = "OrigDist"
origDist.Value = (dstAttachment.Parent.Position - srcAttachment.Parent.Position).Magnitude
origDist.Parent = folder
folder.Parent = player.Character
end
busy = false
end
end
for _,i in pairs(workspace:WaitForChild("Targets"):GetChildren()) do
i.Touched:Connect(function(part)
HandleTouch(i,part)
end)
end
local startSpeed = .2 --texture length per stud per second
local endSpeed = 5 --texture length per stud per second
local rangeSpeed = endSpeed - startSpeed
while script.Parent do
local character = script.Parent
if character then
local folder = character:FindFirstChild("Beam")
if folder and folder:FindFirstChild("SrcRef") and
folder:FindFirstChild("DstRef") and folder:FindFirstChild("Beam") and
folder:FindFirstChild("OrigDist") then
local src = folder.SrcRef.Value
local dst = folder.DstRef.Value
if src.Parent and dst.Parent then
local dist = (src.Parent.Position - dst.Parent.Position).Magnitude
local offset = Vector3.new(0,-((character.HumanoidRootPart.Size.Y/2)+character.Humanoid.HipHeight-.5),0)
local cf = CFrame.lookAt(src.Parent.Position+offset,dst.Parent.Position)*CFrame.Angles(0,0,math.rad(90))
src.CFrame = src.Parent.CFrame:ToObjectSpace(cf)
cf = CFrame.lookAt(dst.Parent.Position,src.Parent.Position+offset)*CFrame.Angles(0,math.rad(180),math.rad(90))
dst.CFrame = dst.Parent.CFrame:ToObjectSpace(cf)
local origDist = folder.OrigDist.Value or dist
folder.Beam.TextureSpeed = math.clamp(rangeSpeed-(rangeSpeed*(dist/origDist))+startSpeed,startSpeed,endSpeed)
end
end
end
task.wait()
end
Its a bit crude and the texture is terrible, but maybe it will get you going in the right direciton.
Thanks a bunch this helped me solve it.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.