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

Position of a corner of a part?

Lets say we have a base named part.

psize = workspace.Part.Size -- Vector3.new(100, 1, 100)
ppos = workspace.Part.Position --Vector3.new(0, 0, 0)

Through scripting I want to find a corner position of this part which would be (50, 0, 50)

I have no clue how to go about this though.

Is there a way to pull the x/y/z values from a vector3 value assigned to a variable?

Thoughts V

Position - (a, b, c) /////// Size - (d, e, f) ///////// (Position+(.5d))+(Position+(.5f)) //// would give me the above corner.

1 answer

✓ Accepted answer

A part has 8 corners. You can get the components of a Vector3 by its x, y, z elements. You don't need to use them, though.

local psize=workspace.Part.Size
local ppos=workspace.Part.Position
local offsets={
	Vector3.new(.5,.5,.5);
	Vector3.new(.5,.5,-.5);
	Vector3.new(.5,-.5,.5);
	Vector3.new(-.5,.5,.5);
}
local corners={}
for _,v in pairs(offsets)do
	corners[#corners+1]=ppos+psize*v
	corners[#corners+1]=ppos-psize*v
end

2 comments

0

hales your code (im trying to change the way I think so I can code better) 10/10

0

made it shorter

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