Arthur123
|
  |
| Joined: 01 Jun 2008 |
| Total Posts: 5347 |
|
|
| 07 Jul 2011 06:38 PM |
| Is there a way to raycast and see if something is occupying space? I think so, if I understand raycasting at least to some degree correctly; so could somebody give me an example... a ray coming out of a part & when it hits something then X() happens.... :D? (or wiki link where it teaches this??) |
|
|
| Report Abuse |
|
|
Arthur123
|
  |
| Joined: 01 Jun 2008 |
| Total Posts: 5347 |
|
|
| 07 Jul 2011 06:50 PM |
| Somebody oughtta know this =P |
|
|
| Report Abuse |
|
|
Shobobo99
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 07 Jul 2011 06:55 PM |
If you wanted to see if there is something inside a space, you would use the FindPartsInRegion3 method of the workspace.
A Region3 is a bounding box and takes two arguements which are positions the first being the bottom left corner and the second being the top right corner.
r3 = Region3.new(Vector3.new(0,0,0),Vector3.new(10,10,10)
Creates a Region3 with a size of 10*10*10 and position of 5,5,5
local PartsInSpace = workspace:FindPartsInRegion3(r3)
And now you have the objects inside that space in a table! |
|
|
| Report Abuse |
|
|
Arthur123
|
  |
| Joined: 01 Jun 2008 |
| Total Posts: 5347 |
|
|
| 07 Jul 2011 07:07 PM |
| Thanks! What about the FindPartOnRay method, how would I use that one? |
|
|
| Report Abuse |
|
|
|
| 07 Jul 2011 07:10 PM |
When using FindPartOnRay, the function will return:
nil, EndPosition(Vector3) |
|
|
| Report Abuse |
|
|
|
| 07 Jul 2011 07:11 PM |
| ... IF the ray doesn't intersect with anything. |
|
|
| Report Abuse |
|
|
Shobobo99
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 07 Jul 2011 07:13 PM |
By creating a Ray which takes two arguements, start position, and direction.
local ray = Ray.new(Vector3.new(0,0,0), Vector3.new(0,0,5))
Would create a ray right? Now with the FindPartOnRay method you can see if there is a part in the way and if there is, the position where the ray intersects the part.
hit, hitpos = FindPartOnRay(ray) print(hit, hitpos)
There is a second and third arguement of the method. The second arguement takes Instances in which the descendants of it will be ignored if intersected and the third arguement sets the max length of the ray. |
|
|
| Report Abuse |
|
|
Arthur123
|
  |
| Joined: 01 Jun 2008 |
| Total Posts: 5347 |
|
| |
|
|
| 07 Jul 2011 07:23 PM |
| Yes. And if hit is 'nil' then that means the ray did not intersect with anything. |
|
|
| Report Abuse |
|
|
Arthur123
|
  |
| Joined: 01 Jun 2008 |
| Total Posts: 5347 |
|
| |
|
Shobobo99
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 5754 |
|
|
| 07 Jul 2011 07:36 PM |
oops I made a mistake.
I meant to say workspace:FindPartOnRay(r3) |
|
|
| Report Abuse |
|
|