make raycast go in a direction infinitely?
So, I'm making a top-down shooter using raycast guns. Now, I know that rays can't be created with infinite lengths (the max distance is 512, I believe?) however I want to make it so that the ray goes straight forward in the direction of the mouse rather than ending at the mouses position. So, like, when you click, rather than the ray going down and ending at the mouse.Hit position, it keeps going straight past the mouse.Hit position and ending after 200 studs. So like the Y position of the mouse isn't taken into factor.
Here's the script for my gun:
01 | local tool = script.Parent |
02 | local player = game:GetService( "Players" ).LocalPlayer |
04 | tool.Equipped:connect( function (mouse) |
06 | mouse.Button 1 Down:connect( function () |
10 | script.Parent.Fire:Play() |
12 | local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 200 ) |
13 | local part, position = workspace:FindPartOnRay(ray, player.Character, false , true ) |
15 | local beam = Instance.new( "Part" , workspace) |
16 | beam.BrickColor = BrickColor.new( "Medium stone grey" ) |
17 | beam.FormFactor = "Custom" |
18 | beam.Material = "Neon" |
19 | beam.Transparency = 0.5 |
22 | beam.CanCollide = false |
24 | local distance = (tool.Handle.CFrame.p - position).magnitude |
25 | beam.Size = Vector 3. new( 0.3 , 0.3 , distance) |
26 | beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new( 0 , 0 , -distance / 2 ) |
30 | beam.Transparency = beam.Transparency + . 1 |
31 | until beam.Transparency = = 0 |
33 | game:GetService( "Debris" ):AddItem(beam, 0.5 ) |
The code is pretty basic; pretty much the same as any other simple raycast gun.
I'm not sure if what I'm asking is even possible, but I figured that I'd have better luck asking smarter people rather than spending headache-inducing hours trying to figure it out myself.
All help is appreciated!