jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 18 Oct 2012 09:26 PM |
There's no way to find the surface of an object that was hit while raycasting, right?
It'd probably require some indirect hardcore math relations between ray angle and object rotation? |
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 18 Oct 2012 09:28 PM |
It is, and the math isn't so 'hardcore'
http://www.roblox.com/Forum/ShowPost.aspx?PostID=52742200 |
|
|
| Report Abuse |
|
|
jewelycat
|
  |
| Joined: 10 Sep 2008 |
| Total Posts: 17345 |
|
|
| 18 Oct 2012 09:38 PM |
| That's so much easier than expected... |
|
|
| Report Abuse |
|
|
xSIXx
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 9202 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 18 Oct 2012 11:53 PM |
| Keep in mind that wedges and spheres also exist, and that you will need to deal with terrain too unless you're never planning on using the code in a place that has terrain. |
|
|
| Report Abuse |
|
|
Shobobo99
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 19 Oct 2012 05:53 PM |
A long while ago I made some code that allowed me to identify the surface hit on a part and this might help you with balls, wedges and cornerwedges. The only thing I did not include was terrain calculations.
local function GetFace(part, pos) local rcframe = CFrame.new(part.CFrame:pointToObjectSpace(pos)) -- relative local wcframe -- world print(rcframe.p)
local size, ppos = part.Size, part.Position if part:IsA("Part") and part.Shape == "Ball" then rcframe = CFrame.new(part.Position, pos) * CFrame.new(0,0,-size.x/2) elseif math.abs(math.abs(rcframe.Z)-size.Z/2) < 0.025 then -- front/back print("FRONT/BACK") rcframe = rcframe.Z < 0 and rcframe or rcframe * CFrame.Angles(0, math.pi, 0) elseif math.abs(math.abs(rcframe.X)-size.X/2) < 0.025 then -- left/right print("LEFT/RIGHT") rcframe = rcframe * CFrame.Angles(0, math.pi/2 * (rcframe.X > 0 and -1 or 1), 0) elseif math.abs(math.abs(rcframe.Y)-size.Y/2) < 0.025 then -- top/bottom print("TOP/BOTTOM") rcframe = rcframe * CFrame.Angles(math.pi/2 * (rcframe.Y < 0 and -1 or 1), 0, 0) elseif part:IsA("CornerWedgePart") then -- Super special print(rcframe.p) local x,y,z = math.abs(rcframe.X),math.abs(rcframe.Y),math.abs(rcframe.Z)
if math.abs(y*(size.X/size.Y) - x) < math.abs(y*(size.Z/size.Y) - z) then -- LEFT print("left") rcframe = rcframe * CFrame.Angles(0,math.pi/2,0) * CFrame.Angles(math.atan(size.X/size.Y),0,0) else -- BACK rcframe = rcframe * CFrame.Angles(-math.atan(size.Z/size.Y),math.pi,0) print("back") end else -- Kinda special print("lol wedge front") rcframe = rcframe * CFrame.Angles(math.atan(size.Z/size.Y),0,0) end
local x,y,z = rcframe:toEulerAnglesXYZ() print(math.deg(x), math.deg(y), math.deg(z)) return rcframe end |
|
|
| Report Abuse |
|
|
Shobobo99
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 19 Oct 2012 05:55 PM |
| Pardon me, but I forgot to mention that the value returned is a cframe value that points perpendicular to the surface it is on, as the intended use for this code is bullet holes. |
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 19 Oct 2012 06:53 PM |
I laughed at 'and this might help you with balls'
kill me |
|
|
| Report Abuse |
|
|