Calculating furthest points of a part

I’m finna feel damn stupid. It doesn’t even sound (and probably isn’t) hard, I just cant.
Also never used devforum so idk how to format stuff properly, sorry if its a mess.

I’ve been so stuck on figuring the furthest points of a part (so I can compare them to the Players position to check if they’re inside an area).

Heres what I got so far (hopefully it formatted properly?). This code has been edited to make a physical representation of what the limits are.

function getParameters(floor)
	local x,x2,y,z,z2 = 0,0,0,0,0
	x = floor.Position + Vector3.new((floor.Size.X/2),0,0)
	x2 = floor.Position + Vector3.new(-(floor.Size.X/2),0,0)
	z = floor.Position + Vector3.new(0,0,(floor.Size.Z/2))
	z2 = floor.Position + Vector3.new(0,0,-(floor.Size.Z/2))
	y = floor.Position.Y
	return x,x2,y,z,z2
end
local fields = game.Workspace.DuellingFields
for i,v in pairs(fields:GetChildren()) do
	local fx,fx2,fy,fz,fz2 = getParameters(v)
	local p = Instance.new("Part", game.Workspace.Mess)
	p.Position = fx
			
	local p1 = Instance.new("Part", game.Workspace.Mess)
	p1.Position = fx2
			
	local p2 = Instance.new("Part", game.Workspace.Mess)
	p2.Position = fz
			
	local p3 = Instance.new("Part", game.Workspace.Mess)
	p3.Position = fz2
end

When I run this, I get this:
side

Clearly, the position of the X and Z have flipped and I can’t figure out why.

If this was an obvious error and I’ve missed it I am so very sorry.
Oh cool you can do emojis here :duck:

p.s. if theres an easier way to do this I’d be very grateful if you could link the wiki page on it, many thanks
-bray

2 Likes

It seems like it DOES work, it just doesn’t account for rotation. Try doing something like this for the function

function getParameters(floor)
	local x,x2,y,z,z2 = 0,0,0,0,0
	x = floor.CFrame * CFrame.new((floor.Size.X/2),0,0)
	x2 = floor.CFrame * CFrame.new(-(floor.Size.X/2),0,0)
	z = floor.CFrame * CFrame.new(0,0,(floor.Size.Z/2))
	z2 = floor.CFrame * CFrame.new(0,0,-(floor.Size.Z/2))
	y = floor.Position.Y
	return x.p,x2.p,y,z.p,z2.p
end
3 Likes

Oh dear. You’re entirely correct and it works- thanks v much!!!

enjoy this :fox_face: as a thanks

1 Like

Happy to help! Be sure to mark my post above as the solution by clicking the little check box so people don’t reply solutions to a solved issue

1 Like

roger roger

1 Like