|
| 19 Dec 2012 06:25 PM |
I am using the FindPartsInRegion3 method along with raycasting, so I can identify all of the pieces that touch the ray. It works some of the time, but not all of the time. What I mean by this is that it sometimes says it isn't touching anything, when it actually is, and vice versa. Is there a fix for this? Or better yet, an alternative way to do this? What I am trying to do is identify if there are any CanCollide = true bricks between to points. Thanks in advance for any help. |
|
|
| Report Abuse |
|
|
Moolah60
|
  |
| Joined: 26 Sep 2009 |
| Total Posts: 654 |
|
|
| 19 Dec 2012 06:41 PM |
| Instead of using :FindPartsInRegion3() why don't you use the :FindPartOnRay() method? That way it'd only detect parts on the actual ray, not outside of it. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2012 06:45 PM |
| Please correct me if I'm wrong, but doesn't the :FindPartOnRay() method only identify the first part it touches? |
|
|
| Report Abuse |
|
|
Moolah60
|
  |
| Joined: 26 Sep 2009 |
| Total Posts: 654 |
|
|
| 19 Dec 2012 06:52 PM |
Yes but I believe that :FindPartsInRegion3() works similarly. Maybe instead of that you can do this:
function newRay(pos) local ray = Ray.new(pos, (game.Workspace.Part.Position - pos).unit * 500) if game.Workspace:FindPartOnRay(ray) then local part,pos = game.Workspace:FindPartOnRay(ray) if part.CanCollide = true then -- your script here end newRay(pos) end end
newRay(Vector3.new(0,0,0))
--game.Workspace.Part is the ending position. |
|
|
| Report Abuse |
|
|
Moolah60
|
  |
| Joined: 26 Sep 2009 |
| Total Posts: 654 |
|
|
| 19 Dec 2012 06:55 PM |
Well I made an error and forgot an equal sign where it checks for CanCollide true, here's the fixed script.
function newRay(pos) local ray = Ray.new(pos, (game.Workspace.Part.Position - pos).unit * 500) if game.Workspace:FindPartOnRay(ray) then local part,pos = game.Workspace:FindPartOnRay(ray) if part.CanCollide == true then -- your script here end newRay(pos) end end
newRay(Vector3.new(0,0,0))
--game.Workspace.Part is the ending position. |
|
|
| Report Abuse |
|
|
Moolah60
|
  |
| Joined: 26 Sep 2009 |
| Total Posts: 654 |
|
|
| 19 Dec 2012 06:57 PM |
Man I'm really off right now, I had two of the same values called in the script(pos was used twice..) hah sorry about that.
function newRay(nPos) local ray = Ray.new(nPos, (game.Workspace.Part.Position - nPos).unit * 500) if game.Workspace:FindPartOnRay(ray) then local part,pos = game.Workspace:FindPartOnRay(ray) if part.CanCollide == true then -- your script here end newRay(pos) end end
newRay(Vector3.new(0,0,0))
--game.Workspace.Part is the ending position. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2012 07:14 PM |
| Although I didn't use that exact code, it gave me an idea that fixed my problem. Thanks! |
|
|
| Report Abuse |
|
|