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: Raycasting help

Previous Thread :: Next Thread 
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
17 Apr 2016 12:05 PM
Ok heres whats up. I'm terrible with raycasting. I'm just here because I need a single function written. I don't care if you try to help teach me about raycasting, I get the concept and how it works. I just don't know the code to write. basically:

MouseButton2Down:connect(function()
send out ray from part, script.Parent.TRGT, in the direction of lookvector
if ray hits a part called streak then
wait(2.5)
if mousebutton2 still down then
script.Parent.Variables.Lock.Value = true
end
end
end)

and i guess on button2 up i'll just make lock = false.
Report Abuse
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
17 Apr 2016 12:06 PM
I suppose i should specify if can be, make the ray the same width and height of part TRGT
Report Abuse
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
17 Apr 2016 12:07 PM
and the ray should travel infinite distance
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
17 Apr 2016 12:11 PM
Ray.new(start,direction)

Rays don't have a width or height, they're just a lil beam shot out in a direction

Try this:
local ignorelist = {} --change to things for ray to ignore, like the part itself and the player

local hit,pos = game.Workspace:FindPartOnRayWithIgnoreList(Ray.new(part.CFrame.p,(part.CFrame.lookVector).unit*9999,ignorelist)

if hit~= nil then
if hit.Name == "streak" then

you figure out the rest
Report Abuse
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
17 Apr 2016 12:13 PM
thank you klga, do i need to stop the ray? how would i if needed?
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
17 Apr 2016 12:14 PM
I don't know of a way to do it if it is possible, but the ray just goes until it hits something or it reaches the end of it's direction
Report Abuse
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
17 Apr 2016 12:15 PM
how fast do rays move?
Report Abuse
DivinePheonix is not online. DivinePheonix
Joined: 30 Mar 2011
Total Posts: 11190
17 Apr 2016 12:16 PM
Read up on this tutorial:
http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun

Replace the line if you want to fire rays with lookVector:
local ray = Ray.new(tool.Handle.CFrame.p, tool.Handle.CFrame.lookVector* 300)

Aswell look at this under Usage for the limitations:
http://wiki.roblox.com/index.php?title=API:Class/Workspace/FindPartOnRay
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
17 Apr 2016 12:20 PM
They don't really glide across the world, they're fast if not instant, it basically just looks in the specified direction until it hits something
Report Abuse
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
17 Apr 2016 02:57 PM
KLGA argument2 is nil with your function
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
18 Apr 2016 01:46 PM
Forgot a parenthesis

local hit,pos = game.Workspace:FindPartOnRayWithIgnoreList(Ray.new(part.CFrame.p,(part.CFrame.lookVector).unit*9999),ignorelist)
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