of     1   

Navydev
#64178721Sunday, March 11, 2012 9:16 PM GMT

Now, don't get me wrong, because the Raycast tutorial, and even making a gun, was fantastic. However, I didn't really feel if it explained anything besides the basics, and when it did, it wasn't enough. The final product for the gun is this: local Tool = script.Parent local User Tool.Equipped:connect(function(mouse) User = Tool.Parent mouse.Button1Down:connect(function() local Ray = Ray.new(Tool.Handle.CFrame.p, (mouse.Hit.p - Tool.Handle.CFrame.p).unit*300) local Hit, Position = game.Workspace:FindPartOnRay(Ray, User) if Hit then if Hit.Parent:FindFirstChild("Humanoid") then Hit.Parent.Humanoid:TakeDamage(30) end end local RayPart = Instance.new("Part", User) RayPart.Name = "Lazer" RayPart.BrickColor = BrickColor.new("Bright red") RayPart.Transparency = 0.5 RayPart.Anchored = true RayPart.CanCollide = false RayPart.BottomSurface = Enum.SurfaceType.Smooth RayPart.formFactor = Enum.FormFactor.Custom local Distance = (Position - Tool.Handle.CFrame.p).magnitude RayPart.Size = Vector3.new(0.2, 0.2, Distance) RayPart.CFrame = CFrame.new(Position, Tool.Handle.CFrame.p) * CFrame.new(0, 0, -Distance/2) game.Debris:AddItem(RayPart, 0.1) end) end) ,and I do not have issues with it. But I did have some questions on what did what. For starters, were exactly did "Position" come from? I found it in this line here: local Distance = (Position - Tool.Handle.CFrame.p).magnitude I remember assigning it a value, but it was this: local = Hit, Position = game.Workspace:FindPartOnRay(Ray, User) What? Ok, I get that the ray uses the ray itself, and to ignore the user(me), but why is it apart of the same local as Hit, for which all I know, does not have a value and must take data later on in the script? The second question, take a look at this line here: RayPart.CFrame = CFrame.new(Position, Tool.Handle.CFrame.p) What is p? Why could I not change it, such as adding a + 3 at the end of it. Is it position? Is it a name for a Vector3 Value? I'm so confused. Lastly, I promise, whats the deal with adding a times 300 in the line: local Ray = Ray.new(Tool.Handle.CFrame.p, (mouse.Hit.p - Tool.Handle.CFrame.p).unit*300) Yes, I know it works, I just don't know why. If I didn't have it there, would the lazer not be long enough? Raycasting is so confusing at first...
NXTBoy
#64182173Sunday, March 11, 2012 10:07 PM GMT

    local Hit, Position = game.Workspace:FindPartOnRay(Ray, User) That's multiple assignment. FindPartOnRay returns two values. As a simple example, you can do this:     local a, b = 2, 3 --- > What is p? Why could I not change it It's a Vector3 --- >  whats the deal with adding a times 300 in the lin It makes the ray cast 300 studs before giving up
devRedd
#64182940Sunday, March 11, 2012 10:19 PM GMT

And now ROBLOX has added a new feature to raycasting that features terrain(which before it was added worked better) which allows the raycast to sense terrain, which would go like this local Hit, Position = game.Workspace:FindPartOnRay(Ray, User, true) where the true is a Boolean value that tells the function FindPartOnRay if it wants to sense the terrain, if you did not want this, you would then put false
Candymaniac
#64214685Monday, March 12, 2012 4:30 PM GMT

So wait... if you set it to false, will it just go through the terrain? I've never worked with terrain before honestly... "Knowledge talks, wisdom listens."
ChocCookieRaider
#64217928Monday, March 12, 2012 6:22 PM GMT

Raycasting is so common on the forums it gets boring. Why can't it be something different and new for once?
Navydev
#64253031Tuesday, March 13, 2012 3:25 AM GMT

I've never seen a ray casting question on the forums before. But if it is, sorry, because its sort of a hard topic to grasp at first as a beginner coder.
DestinyUnbound
#64259320Tuesday, March 13, 2012 7:34 AM GMT

I have done a lot with raycasting, and I have came up with a way to give a raycast gun realistic recoil shot bloom. You are still on the easy stuff.
Navydev
#64297036Wednesday, March 14, 2012 1:16 AM GMT

Jiggle the player's camera, and add a bit of smoke, and your good to go.
DestinyUnbound
#64320492Wednesday, March 14, 2012 6:31 PM GMT

if I am going for realism, the recoil spread bloom is for playability (it makes it more professional and better for accuracy with controlled fire).

    of     1