Hello all! I am posting here again because I have tried many ways to accomplish this but I can’t figure out how. Essentially what I want to do is have a modulescript where you can specify 2 vector3’s and it will create a part to fit in between these positions.
This is not too difficult to do, you can use :Lerp() (go far down to find it) on any Vector3 to lerp it towards another Vector3! For example (semi psuedo code):
someVectorHere:Lerp(otherVectorHere, .5)
would give you the center between the 2 vectors!
Example where i make a straight line between 2 parts:
local subVector = (workspace.Start.Position - workspace.End.Position) --I call it subVector cause i have no idea what else to name it
--(subtracted vector)
----------
local newPart = Instance.new("Part")
newPart.Size = Vector3.new(subVector.Magnitude, 1, 1) --Make the part length the distance from the start to end
newPart.Position = workspace.Start.Position:Lerp(workspace.End.Position, .5) --Position it between them
newPart.Orientation = subVector.Unit --This will rotate the part to be a straight line from A to B
newPart.Anchored = true
newPart.CanCollide = false
newPart.Parent = workspace
(this can be greatly simplified and reduced in lines, i only left it verbose for the reply!)
Which, assuming you have this layout:
Results in this:
If you need more explanation or help feel free to reply!
Would this increase the part’s size in all directions aswell? like for example if I wanted to fill an area and I put the start part in the bottom left corner of the room, and the end part in the top right corner of the room, would the part fill the entire area?
No it would create a line from the start part to the end part, a slight modification to the code i wrote would do the trick though!
(I will try to make an example give me a second)
Thank you! I’ve been searching around on the devforum a lot for this and I’m trying to make a chunk system for my game where you can create a chunk between two vector3 positions but I could never find how to fill in an area.
Interesting! Also i am having trouble trying to make it size correctly hence the slow response, apologies
It’s fine. I really am not in a hurry.
Yeah i am sorry i seem to be unsuccessful and admit defeat! Anyone else who sees this, feel free to step in. I hope what i was able to do helped a little!
dayummm big brain
Hey! I’m not sure if this is what you’re looking for, but this method works for me:
local LeftPart = game.Workspace.LeftPart
local RightPart = game.Workspace.RightPart
local CenterPart = game.Workspace.CenterPart --This is the part you want to fit in between the vectors.
CenterPart.CFrame = CFrame.LookAt(LeftPart.CFrame, RightPart.CFrame)
CenterPart.Position = (LeftPart.Position + RightPart.Position) / 2
You can set the size to anything you want, again let me know if anything isn’t working
This is a step in the right direction, but let me explain it here so anyone else can understand fully what i’m trying to achieve.
I want to fill between 2 positions (vector3), Not make a line between two positions, but fill a square part between two positions. I want to be able to specify the bottom left corner and top right corner vector3’s, and have a script calculate the size between those two positions and create a part there. The part would be filled between the two locations.
Yes this is a perfect example, I was just about to make one.
To get that “square” fill almost like a region3 I think youd need something like:
part.Position = (pos1+pos2)/2
local diff = pos2-pos1
part.Size = Vector3.new(math.abs(diff.X),math.abs(diff.Y),math.abs(diff.Z))
Thank you, it works like a charm!