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: Can someone explain Rays/Raycasting to me a bit?

Previous Thread :: Next Thread 
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
21 Feb 2017 03:11 PM
Wiki isn't providing me with enough information I feel.

Like how would I make it so a player hovers off the ground 5 studs above what ever type of terrain it's on?
How do I make the player stay 5 studs above any level of the terrain?

That's what rays are used for, but how would I use them for what I am wanting to do?


ATR'er since 2013.
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:21 PM
The ###iest way to describe a ray is to imagine it like a laser pointer. The ###er is emitted from the ###er pointer, and the ###t####r##### ###er hits is what raycasting is used to get.

Here's an example of raycasting, sort of based on what you were asking about:

local char = script.Parent

local debugPointer = Instance.new("Part")
debugPointer.Shape = "Ball"
debugPointer.Anchored = true
debugPointer.CanCollide = false
debugPointer.Size = Vector3.new(0.2,0.2,0.2)
debugPointer.Material = "Neon"
debugPointer.Parent = char

while wait() do
local origin = char.PrimaryPart.Position
local target = origin - Vector3.new(0,5,0)
local offset = (target-origin)
local ray = Ray.new(origin,offset)
local hit,pos,norm,mat = workspace:FindPartOnRay(ray,char)
pr##############ESULTS")
pr################# pr###################### #r##############ormal:",norm)
print("Material:",mat)
if hit ~= nil then
debugPointer.Color = Color3.new(0,1,0)
else
debugPointer.Color = Color3.new(1,0,0)
end
debugPointer.CFrame = CFrame.new(pos)
end
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:21 PM
local char = script.Parent local debugPointer = Instance.new("Part") debugPointer.Shape = "Ball" debugPointer.Anchored = true debugPointer.CanCollide = false debugPointer.Size = Vector3.new(0.2,0.2,0.2) debugPointer.Material = "Neon" debugPointer.Parent = char while wait() do local origin = char.PrimaryPart.Position local target = origin - Vector3.new(0,5,0) local offset = (target-origin) local ray = Ray.new(origin,offset) local hit,pos,norm,mat = workspace:FindPartOnRay(ray,char) print("RAYCAST RESULTS") print("Hit:", hit) print("Position:", #### ############## Normal:", norm) print("Material:", mat) if hit ~= nil then debugPointer.Color = Color3.new(0,1,0) else debugPointer.Color = Color3.new(1,0,0) end debugPointer.CFrame = CFrame.new(pos) end
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:21 PM
roblox's filter is the worst :(
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:22 PM
This is what the prints are supposed to be (hoping this posts correctly, it probably wont :S) print("RAYCAST RESULTS") ################# ###################### ############## Normal:",norm) print("Material:",mat)
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
21 Feb 2017 03:23 PM
Kind of hard to understand with the hashtags, but I'll try my best...
Thanks Clone! I'm a big fan :)


ATR'er since 2013.
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:23 PM
########### ##########
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:25 PM
Okay since Roblox's filter doesn't want to play nice, I'll try to explain what I was doing.

I was printing the results of the 4 return variables.
The first variable returned is the part that was hit by the ray (or nil if it didn't hit anything)
The second variable returned is the position where the ray hit at, or where it was cut off short.
The third variable is the surface normal of the part that was hit, which is basically a directional vector for the face that was hit by the ray.
The fourth variable is the material that was hit by the ray.
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:27 PM
Here's some articles on raycasting (that aren't filtered... lol) ################################################# #####################################################################
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
21 Feb 2017 03:28 PM
HOW IRONIC, THEY GOT FILTERED LMAO.

http://wiki.roblox.com/index.php?title=Raycasting
http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun
Report Abuse
UnjoinedParts is not online. UnjoinedParts
Joined: 01 Jan 2017
Total Posts: 1359
21 Feb 2017 03:29 PM
hey there clone


Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
21 Feb 2017 03:33 PM
Looks like a little more than Lua code needs to be fixed here.
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