Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Region3 rotation for placement system?

My question: Rotating a Region3

I am making a placement system for a game and need collision. I am trying to use Region3s but when I rotate my model the region does not. I do not know if rotating Region3s is possible. Anyway here is my code for the Region3.NOTE: everything is inside of a LocalScript in a gui in StarterGui.

This is in the function that starts placement (Sets properties)

Code samples

regionPart1 = (model.PrimaryPart.Position - (model.PrimaryPart.Size / 2))
regionPart2 = (model.PrimaryPart.Position + (model.PrimaryPart.Size / 2))
	
while true do -- So it updates the region
	region = Region3.new(
		regionPart1, regionPart2
	)
			
	wait(0, 1)
end

Here is my collision detection code:

-- Detecting collision 

-- This is in the movement function so it gets called every time the mouse moves

regionPart1 = (model.PrimaryPart.Position - (model.PrimaryPart.Size / 2))	-- Update
regionPart2 = (model.PrimaryPart.Position + (model.PrimaryPart.Size / 2))

for i, v in pairs(modelInRegion) do
	if v.Parent:FindFirstChild("Primary") ~= nil then
		ModelsFound[v.Parent.Primary.Name] = v.Parent.Primary
		isColliding = true
	else
		isColliding = false
	end
end
		
for index, value in pairs(ModelsFound) do
	spawn(function()
		isColliding = true
	end)
end

Failed solution

I have tried updating the CFrame of the region when the model rotates like this:

region.CFrame = CFrame.new(regionPart1, regionPart2) * CFrame.Angles(0, math.rad(Rot), 0)

In the output it said CFrame could not be set.

End

If there is anyway to rotate a Region3 by 90 degrees then let me know (Not asking for a whole script just either the place to find the answer or a explanation of how it works)! Thanks for helping!

(Also if there is a better way to detect collision then that would also be helpful)

1 comment

0

All the code is in a local script

1 answer

✓ Accepted answer

Region3 cannot be rotated. That being said there are some community made solutions to this.

For example, I created a module that can calculate rotated region3s. This may be best suited for your situation as I specifically built the module to be very similar to the standard region3 API thus it should fit into your current code easy peasy.

Another alternative is to use this trick.

There are plenty of other solutions to this problem but you will have to dig for them.

Good luck!

1 comment

0

Thank you I will test them both out!

This discussion is preserved as it was. New answers, comments, and votes are closed.