generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Raycast Surface Hit

Previous Thread :: Next Thread 
jewelycat is not online. 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 is not online. 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 is not online. jewelycat
Joined: 10 Sep 2008
Total Posts: 17345
18 Oct 2012 09:38 PM
That's so much easier than expected...
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
18 Oct 2012 09:42 PM
hurrrrrrrrr
Report Abuse
stravant is not online. stravant
Forum Moderator
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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image