Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Position of a corner of a part?

Asked by 8 years ago

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

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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
0
*hales your code* (im trying to change the way I think so I can code better) 10/10 magiccube3 115 — 8y
0
made it shorter 1waffle1 2908 — 8y
Ad

Answer this question