of     1   

hlelo_wolrd
#66477861Tuesday, April 17, 2012 1:03 AM GMT

I want to get the surface normal of a surface on block A. I have the CFrame of block A and I have a position on the surface of block A. The most important question is how to find exactly which surface of block A my position is located against.
Anaminus
Top 100 Poster
#66481622Tuesday, April 17, 2012 1:51 AM GMT

I stumbled across this by accident while trying to find a way to select the *edge* of a part: local function NumNormal(n) return n == 0 and 0 or n/math.abs(n) end local function GetSurfaceNormal(part,point) local p = part.CFrame:toObjectSpace(CFrame.new(point)).p local s = part.Size local ax,ay,az = math.abs(p.x/s.x),math.abs(p.y/s.y),math.abs(p.z/s.z) return Vector3.new(NumNormal(p.x),NumNormal(p.y),NumNormal(p.z)) * Vector3.new( (ax>ay and ax>az) and 1 or 0, (ay>ax and ay>az) and 1 or 0, (az>ax and az>ay) and 1 or 0 ) end Here's the nearest edge function as well, if you're interested: local function GetNearestEdge(part,point) local p = part.CFrame:toObjectSpace(CFrame.new(point)).p local s = part.Size local ax,ay,az = math.abs(p.x/s.x),math.abs(p.y/s.y),math.abs(p.z/s.z) return Vector3.new(NumNormal(p.x),NumNormal(p.y),NumNormal(p.z)) * Vector3.new( (ax>ay or ax>az) and s.x or math.abs(p.x), (ay>ax or ay>az) and s.y or math.abs(p.y), (az>ax or az>ay) and s.z or math.abs(p.z) ) end
Anaminus
Top 100 Poster
#66481949Tuesday, April 17, 2012 1:55 AM GMT

Whoops! Don't forget to divide the part's Size by 2 like I just did.
hlelo_wolrd
#66486436Tuesday, April 17, 2012 3:02 AM GMT

Now how do I take that normal and "rotate" it? How do I take any vector direction and "rotate" it by CFrame?
hlelo_wolrd
#66487457Tuesday, April 17, 2012 3:21 AM GMT

HUZZAH. DID IT.             local normal = GetSurfaceNormal(hitPart,hitPoint)             normal = (CFrame.new(Vector3.new(0,0,0),normal) * hitPart.CFrame).lookVector
Oysi93Creator2
#66498764Tuesday, April 17, 2012 2:18 PM GMT

@Anaminus part.CFrame:toObjectSpace(CFrame.new(point)).p is the same as part.CFrame:pointToObjectSpace(point) ^_^
Gordonlai
#66499099Tuesday, April 17, 2012 2:31 PM GMT

There's a CFrame plugin available for ROBLOX Studio. You can download it off some sites. It's much more easier to do CFraming in ROBLOX Studio, especially when you have the plugin.
Oysi93Creator2
#66500134Tuesday, April 17, 2012 3:15 PM GMT

You apparently don't understand, Gordon. You see, he wants to do this through a script. He needs to do it through a script. This is to make his game not be like all the extra-ordinarily bad ones on the front page. And I can't even begin to explain how stupid it is to tell him to use a plugin. Because, primarily, it means you should just get the hell out of this place.
badfitz67
#176700749Thursday, October 22, 2015 8:51 PM GMT

DAMN OYSI WAS A NERD ROASTER Never too late to change a life, sir.
thesupremegamer
#176700868Thursday, October 22, 2015 8:53 PM GMT

OHHHHHHHHH REKTTTTTT Sorry my BillabobIgnus typed that.
Happywalker
#176700944Thursday, October 22, 2015 8:54 PM GMT

necro bump
Exanimatedn9dean
#227600839Thursday, November 16, 2017 6:40 AM GMT

necro bump [2]

    of     1