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

Get part's size angle (x,y,z) relative to another part? [answered]

My code works fine but there is way too much checking involved and doesn't even include the part's X or Z orientation.

The variable that needs changing is the PartXChange and PartZChange. I have another variable called PartYChange I just haven't included it

These 3 variables are for where the part's size (x,y,z) are relative to another part

if boundary then
					print(Part.Orientation.Z)
					print(Part.Orientation.X)
				if Part.Orientation.Y <= -90 then --Starts check here
					PartXChange1 = Part.Size.Z
					PartXChange2 = -Part.Size.Z
				elseif Part.Orientation.Y <= 0 then
					PartXChange1 = -Part.Size.X 
					PartXChange2 = Part.Size.X 
				elseif Part.Orientation.Y <= 90 then
					PartXChange1 = Part.Size.Z
					PartXChange2 = -Part.Size.Z
				elseif Part.Orientation.Y <= 180 then
					PartXChange1 = -Part.Size.X 
					PartXChange2 = Part.Size.X 
				end
				
				if Part.Orientation.Y <= -90 then
					PartZChange1 = Part.Size.X
					PartZChange2 = -Part.Size.X
				elseif Part.Orientation.Y <= 0 then
					PartZChange1 = -Part.Size.Z
					PartZChange2 = Part.Size.Z
				elseif Part.Orientation.Y <= 90 then
					PartZChange1 = Part.Size.X
					PartZChange2 = -Part.Size.X
				elseif Part.Orientation.Y <= 180 then
					PartZChange1 = -Part.Size.Z
					PartZChange2 = Part.Size.Z
				end	--Ends here
				
			local v3 = boundary.CFrame:PointToObjectSpace(Part.Position)
				if math.abs(PartXChange2 / 2 + v3.X) <= boundary.Size.X / 2 and math.abs(Part.Size.Y / 2 + v3.Y) <= boundary.Size.Y / 2 and math.abs(PartZChange1 / 2 + v3.Z) <= boundary.Size.Z / 2 then
				Inboundary = true
				else
				Inboundary = false
				end

			if math.abs(PartXChange1 / 2 + v3.X) <= boundary.Size.X / 2 and math.abs(-Part.Size.Y / 2 + v3.Y) <= boundary.Size.Y / 2 and math.abs(PartZChange2 / 2 + v3.Z) <= boundary.Size.Z / 2 then
				Inboundary2 = true
				else
				Inboundary2 = false
			end

I know this is kind of bland but the title says it all. So, how could I go about this?

1 answer

Finally, after many hours I've managed to get it done. Here is my end result that I am happy with:

local v3 = boundary.CFrame:PointToObjectSpace(Part.Position)
					local vRelative = boundary.CFrame:PointToObjectSpace(Part.Size)			
										
					if  math.abs(vRelative.X / 2 + v3.X) <= math.abs(vRelative.X / 2 - boundary.Size.X / 2 + Part.Size.X / 2) and 
						math.abs(vRelative.Y / 2 + v3.Y) <= math.abs(vRelative.Y / 2 - boundary.Size.Y / 2 + Part.Size.Y / 2) and 
						math.abs(vRelative.Z / 2 + v3.Z) <= math.abs(-vRelative.Z / 2 - boundary.Size.Z / 2 + Part.Size.Z / 2) then
						Inboundary = true
					else
						Inboundary = false
					end

					if -vRelative.X / 2 + v3.X <= math.abs(-vRelative.X / 2 + boundary.Size.X / 2 - Part.Size.X / 2) and 
						-vRelative.Y / 2 + v3.Y <= math.abs(-vRelative.Y / 2 + boundary.Size.Y / 2 - Part.Size.Y / 2) and 
						math.abs(-vRelative.Z / 2 + v3.Z) <= math.abs(vRelative.Z / 2 + boundary.Size.Z / 2 - Part.Size.Z / 2) then
						Inboundary2 = true
					else
						Inboundary2 = false
					end

					if Inboundary == true and Inboundary2 == true then
						mouseTarget.Position = position
					else
						Part:Destroy()
					end

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