Hello Everybody, Wanna start off with I’m not looking for code, I’m looking for ideas to what I should use to do something in coding. I have been scripting a build mode recently and have a wall building system. Players can freely place walls on a grid like Roville/ Welcome to Bloxburg/ Sims. The problem I have is if a player places a wall where there are several walls to connect to I need to figure out which wall I need to connect to, which I’m using the method of finding the biggest pairs of walls to just connect them except for some situations. The ideas I’ve had is use magnitude, but that hasn’t really worked out due to the size of the walls can vary based on what the player sets the length as, and everytime I get try to get the angle it fails due to the player can place the wall fowards or backwards so it never get’s the largest angle due to all the solutions I’ve found from other topics have been based on two points. Below is the angles it’s suppose to be picking. Basically my question in general is what’s the best way to find the biggest angle to connect it to or if I should try something else than trying to find the angle for the same result.
You should split your text into paragraphs so it’s easier to read
So from what I understand you want to combine the walls that are the closest to being straight.
Vector of the red wall = LeftPoint - MiddlePoint
Vector of the blue wall = MiddlePoint - RightPoint
Then you can calculate the angle by doing RedVector:Dot(BlueVector)
Compare that with each wall and you can find what you’re looking for.
Letme test your idea, give me about 20 minutes, if it works, I’ll mark your post as solution! PS: Sorry about the hard to read post.
Hm, I tried your idea, but I think you may of missed the part where the player can place a wall in either direction. This was my code I came up with, and it is changed a lot depending on the parts orientation.
local function Angle(P1, P2, P3)
local Check1 = (P1 - P2)
local Check2 = (P2 - P3)
print(Check1:Dot(Check2))
end
Angle((workspace.WallPartMain.CFrame * CFrame.new(workspace.WallPartMain.Size.X/2, 0, 0)).Position, (workspace.WallPartMain.CFrame * CFrame.new(workspace.WallPartMain.Size.X/-2, 0, 0)).Position, (workspace.WallExtension.CFrame * CFrame.new(workspace.WallPartMain.Size.X/2, 0, 0)).Position)
Angle((workspace.WallPartMain.CFrame * CFrame.new(workspace.WallPartMain.Size.X/2, 0, 0)).Position, (workspace.WallPartMain.CFrame * CFrame.new(workspace.WallPartMain.Size.X/-2, 0, 0)).Position, (workspace.WallExtension2.CFrame * CFrame.new(workspace.WallPartMain.Size.X/2, 0, 0)).Position)
That’s why I said LeftPoint
, MiddlePoint
and RightPoint
with a picture, because with your current code if the wall is placed the other way around LeftPoint
and MiddlePoint
will be switched.
As long as you give the correct arguments it will work.