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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 21 Feb 2017 03:21 PM |
| roblox's filter is the worst :( |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 21 Feb 2017 03:27 PM |
| Here's some articles on raycasting (that aren't filtered... lol) ################################################# ##################################################################### |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
|
| 21 Feb 2017 03:33 PM |
| Looks like a little more than Lua code needs to be fixed here. |
|
|
| Report Abuse |
|
|