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 » Scripting Helpers
Home Search
 

Re: With the new raycasting...

Previous Thread :: Next Thread 
Arthur123 is not online. 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 is not online. Arthur123
Joined: 01 Jun 2008
Total Posts: 5347
07 Jul 2011 06:50 PM
Somebody oughtta know this =P
Report Abuse
Shobobo99 is not online. 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 is not online. 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
crazyman32 is online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
07 Jul 2011 07:10 PM
When using FindPartOnRay, the function will return:

nil, EndPosition(Vector3)
Report Abuse
crazyman32 is online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
07 Jul 2011 07:11 PM
... IF the ray doesn't intersect with anything.
Report Abuse
Shobobo99 is not online. 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 is not online. Arthur123
Joined: 01 Jun 2008
Total Posts: 5347
07 Jul 2011 07:22 PM
Is hit the object then?
Report Abuse
crazyman32 is online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
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 is not online. Arthur123
Joined: 01 Jun 2008
Total Posts: 5347
07 Jul 2011 07:30 PM
Awesome, thanks.
Report Abuse
Shobobo99 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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