Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Make a part that links two points?

Asked by
Roytt 64
7 years ago
Edited 7 years ago

This is what I currently have

part.CanCollide = false
        part.Name = "Ray"
        part.Anchored = true
        part.BrickColor = BrickColor.new("Crimson")
        part.Transparency = .4
        part.Size = Vector3.new((mob.Head.Position -    centerOfTheMap.Position).magnitude,.2,.2)
        part.Position = ((mob.Head.Position+centerOfTheMap.Position)/2)

        part.Parent = workspace

But I don't quite grasp how CFrame works and I can't seem able to make the part go through two point's in space.

2 answers

Log in to vote
0
Answered by 7 years ago

Working with CFrame is a lot like working with Part.Position, though there is a difference. Whenever you change a Part's position or rotation in space, you should use CFrame, not Part.Position. Using Part.Position can create unwanted and unexpected effects. It is quite simple, actually:

part.CanCollide = false
part.Name = "Ray" --Note, of course, that you don't have to indent
part.Anchored = true
part.BrickColor = BrickColor.new("Crimson")
part.Transparency = .4
part.Size = Vector3.new((mob.Head.Position -    centerOfTheMap.Position).magnitude,.2,.2)
part.CFrame = CFrame.new((mob.Head.Position+centerOfTheMap.Position)/2) --Instead of position, with Vector3.new, use CFrame, with CFrame.new
part.Parent = workspace

This is the Wiki page for CFrames, since there is lots more that you can do with it: http://wiki.roblox.com/index.php?title=CFrame

0
Doesn't work, the part doesn't connect the two points but goes horizontally between them. Roytt 64 — 7y
0
What exactly are you trying to do here? Do you mean you want to resize a part so it is bridging two points in space? jamesarsenault 192 — 7y
Ad
Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

To create a part between two points:

--create the points
local pos1 = Vector3.new()
local pos2 = Vector3.new(10,10,10)
--get information
local diff = pos2-pos1
local dist = diff.magnitude
local center = pos2 - (diff/2)
--create the part
local part = Instance.new('Part',workspace)
part.Anchored=true
--simple
part.Size = Vector3.new(1,1,dist)
--first argument is position, second argument is what to look at...
part.CFrame = CFrame.new(center,pos2)

Answer this question