|
| 13 Mar 2012 07:52 PM |
Given a point on the surface of a block, how does one determine the normal to the block's surface? Thank you for your help.
Sincerely, Noobertuber |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2012 08:14 PM |
Clarification: Point on block surface is given by a raycast to the brick.
Sincerely, Noobertuber |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2012 09:55 PM |
At three bumps, this is moving to scripters.
Sincerely, Noobertuber |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2012 10:16 PM |
| What exactly do you mean the normal to the face of the block? |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 13 Mar 2012 10:39 PM |
| Are you asking how to tell which face it is on based on a point? |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2012 10:55 PM |
Normal... Unit vector perpendicular to the plane of the surface of the block. (Or tangent of a sphere).
Yes, SDuke, or rather the unit vector of the surface. For spheres, I know, you merely take the hit position and subtract it from the sphere's position, and take the unit of that value. What I do not know is how to do that with other bricks. (bocks and cylinders)
Sincerely, Noobertuber
|
|
|
| Report Abuse |
|
|
Shobobo99
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 13 Mar 2012 11:39 PM |
The only way I know of achieving this is by first getting the position of the hit position relative to the block's CFrame. For example:
local hPos = --Hit Position local rCFrame = block.CFrame -- Orientation and position of block local s = block.Size
local hRelativePos = rCFrame:pointToObjectSpace(hpos) local face = ""
if hRelativePos.Z == s.Z/2 then -- Front / Back surface face = hRelativePos.Z > 0 and "Front" or "Back" elseif hRelativePos.X == s.X/2 then -- Right / Left surface face = hRelativePos.X > 0 and "Right" or "Left" elseif hRelativePos.Y == s.Y/2 then -- Top / Bottom surface face = hRelativePos.Y > 0 and "Top" or "Bottom" end |
|
|
| Report Abuse |
|
|
Shobobo99
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 13 Mar 2012 11:43 PM |
Oh, that will just give you a string, I forgot that you wanted the normal.
local hPos = --Hit Position local rCFrame = block.CFrame -- Orientation and position of block local s = block.Size
local hRelativePos = rCFrame:pointToObjectSpace(hpos) local normal
if hRelativePos.Z == s.Z/2 then -- Front / Back surface normal = hRelativePos.Z > 0 and rCFrame*CFrame.new(0,0,-1).lookVector or rCFrame*CFrame.new(0,0,1).lookVector elseif hRelativePos.X == s.X/2 then -- Right / Left surface normal = hRelativePos.X > 0 and rCFrame*CFrame.new(1,0,0).lookVector or rCFrame*CFrame.new(-1,0,0).lookVector elseif hRelativePos.Y == s.Y/2 then -- Top / Bottom surface normal = hRelativePos.Y > 0 and rCFrame*CFrame.new(0,1,0).lookVector or rCFrame*CFrame.new(0,-1,0).lookVector end |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 14 Mar 2012 12:23 AM |
n:Dot(x0-x1)=0
Is the equation of a plane so just simply solve for which face it intersects.
local faces={{"y","Top"},{"y","Bottom"},{"z","Front"},{"z","Back"},{"x","Left"},{"x","Right"}};
function findNormal(part,point) local c=part.CFrame; for _,v in pairs(faces) do local n=c*Vector3.FromNormalId(Enum.NormalId[v[2]]); local offset=Vector3.new( v[1]=='x' and part.Size.x/2 or 0, v[1]=='y' and part.Size.y/2 or 0, v[1]=='z' and part.Size.z/2 or 0 ); local x0=n*offset; if n:Dot(x0-point)==0 then return n; end end end |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2012 12:12 PM |
You could use the pointToObjectSpace method of a CFrame to avoid that ugly table stuff.
function findNormal(part, point) local offset = part.CFrame:pointToObjectSpace(point) local x, y, z = math.abs(offset.x), math.abs(offset.y), math.abs(offset.z) local sx, sy, sz = part.Size.x/2, part.Size.y/2, part.Size.z/2 if x==sx then if y < sy and z < sz then y = 0 z = 0 end elseif y==sy then if x < sx and z < sz then x = 0 z = 0 end elseif z==sz then if x < sx and y < sy then x = 0 y = 0 end end return Vector3.new(x/sx, y/sy, z/sz) end
|
|
|
| Report Abuse |
|
|
|
| 14 Mar 2012 04:22 PM |
Thanks. One more question: what about wedges, cylinders, and the like?
Sincerely, Noobertuber |
|
|
| Report Abuse |
|
|
|
| 14 Mar 2012 06:32 PM |
| I'm not sure the kind of faces a Wedge has. Cylinders would be a bit more difficult and involve a bit more math because of their rounded feature. |
|
|
| Report Abuse |
|
|
link7002
|
  |
| Joined: 26 May 2009 |
| Total Posts: 545 |
|
|
| 14 Mar 2012 06:49 PM |
| You feel kinda dumb when you don't understand the what other people are saying, and then bother to post about it. lol |
|
|
| Report Abuse |
|
|