Wall corners fix?

I’m using marching squares algorithm to generate a “dungeon”, but there is an issue.
The walls have gaps in the corners:
image
image
My current code for walls generation is:
image
I took a look at the stravant plugin, but I don’t know how to adapt it to my code.

1 Like

Maybe extend the width, from the X or Y; whatever coordinate you choose to extend it to be wider.

That only works in 90-180 deg.

Hm… Maybe do something with the unioning two parts by combining two parts together. You know how there’s a plugin that allows you to connect one part to another when it’s far. It has to do with something to add a new part and connecting it to the next part.

You can use your original solution and build 2 “triangles” (4 wedgeparts) to fill in the gap.
Assuming we only care about the X and Z axes (that is, the height and Y position of the walls are the same): let A and B be the exposed outer vertices of the previous wall and C, D be the exposed outer vertices of the current wall. A top-down view (the black lines that aren’t the axes are the walls):

Building a “triangle” (I refer to them as triangles because we’re reasoning about them in 2 dimensions using triangles, but when you actually build them they would be triangular prisms) can be thought of as building 2 right triangles:

Correction: the first right triangle on the left should be RightTraiangle(A, B, X) not RightTriangle(A, C, X)! This has been fixed in the image.

2 Likes

Let’s say that you have two walls:
image
We extract vector a and vector b.
Now calculate the angle between them

local theta = math.acos(a.unit:Dot(b.unit));

Now let’s say that the thickness of the wall is X.
We calculate how much do we have to resize the wall in the direction the walls collide:

local add = X * math.tan(math.pi/2 - theta/2);
if theta <= math.pi / 2 then
	add = -add;
end
add = add/2;

‘add’ is how longer the both walls have to be in the collision spot.

The problem is the next, I can’t get the “b” wall because the system is automatic, maybe I can use raycast, but isn’t the best way.

Should be as simple as

-- part is the current wall, last is the last wall
if last then
	local A = last.CFrame * Vector3.new(0, 0, sizelast.Z/2)
	local B = last.CFrame * Vector3.new(0, 0, -sizelast.Z/2)
	local C = part.CFrame * Vector3.new(0, 0, -sizepart.Z/2)
	local D = part.CFrame * Vector3.new(0, 0, sizepart.Z/2)

	Triangle(A, B, C)
	Triangle(A, C, D)
end

last = part

I have seen a similar topic that had the same problem. The topic is solved, so maybe it could help you. Here is the topic: Filling gaps (like starvants plugin) but live in game

That’s what I suggested in my reply.

1 Like

My bad, I did not notice it. Apologies.

1 Like

I’m not that good at math, but what if you used cylinders/ball shapes to hide the gaps?

That works, but isn’t the best way because the player will have more memory in the place.

You could unload those that are out of sight though.
And doubt if it’s a lot of memory, I’ve seen games with tons of parts performing just fine.

I personally think this is the best solution to this issue, and its the one I’ve implemented. There are a few issues with it however, for example it seems to be somewhat unreliable? It occasionally produces shapes like this, and I’m unsure why, the maths looks fine.

I can’t think why this would an expected product of the math we’ve used, do you think otherwise?

1 Like