Filling gaps (like starvants plugin) but live in game

Now it is not adjusting the wall at all, is it perhaps due to thresh size?

I tried printing thresh and it turned out as 6.1232339957368e-17

You know, this chunk of code has given me an unusual amount of problems. Turns out the variable names are somewhat deceiving in this case:

	local function place()
		if leftWall then
			adjust(wall, leftWall)
		end
		if rightWall then
			adjust(rightWall, wall)
		end
		walls[wall] = true
	end

The leftWall and rightWall can be set without rightIsFound or leftIsFound being set. This is due to the fact that sometimes there are two walls on the right and none on the left, so one right wall is considered the left wall.

I adjusted the code from leftIsFound to leftWall too before, didnā€™t work. The issue still persists. I am currently trying to locate the bug with prints and the closest I have come is that the code doesnā€™t have a chance to return place, or maybe rather, it is not returning place when (below) is executed

if not next(walls) then
print("4")
return place
end

Also!

local thresh = math.cos(math.pi/2)
	if (leftDot) >= thresh and (rightDot) >= thresh then
		print("4")
	return place
end

doesnā€™t get executed either

Argh! Forgot () for place when I am returning the function.
change ā†’ return place()
Another issue surface though, now it is adjusting no matter the angle because this doesnā€™t get executed now.

local thresh = math.cos(math.pi/2)
if (leftDot) >= thresh and (rightDot) >= thresh then
	print("4")
	return place()
end

What I am worried about is the result of thresh. math.cos(math.pi/2) turns out to be really small.

The cosine of 90 degrees or pi/2 is 0, so the smaller the better. the cosine ranges between [-1 1], the x on the unit circle. At 90 degrees the vector is pointing straight up and has no x component, only y. This is why sine of 90 degrees or pi/2 is 1. The results of sine/cosine are not 100% accurate for speed, and even if it were calculated to a greater precision would still be limited by floating point representations.

place should be returned, not place().

Give me a bit and Iā€™ll look into it more later, Iā€™m being distracted at the moment. Iā€™ll also setting up a VBox and will test it out myself.

2 Likes

Here is a place file containing a working version of the wall script with thresholds. Turns out we needed to make sure that the cosine was less than the threshold. The angle in the script is set to 45 degrees or pi/4.
Walls.rbxl (19.9 KB)

5 Likes