MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 29 May 2012 03:42 PM |
So, I got the Raygun script from the Wiki, and how could I add a Spread to the bullet? Only at the end of it though, I tried but I couldn't. Here's what I came up with:
local Tool = script.Parent local User local Spread = 10 local Automatic = false --Set to false for semi. local Firing = false local FireRate = 0.075
Tool.Equipped:connect(function(mouse) User = Tool.Parent function Fire() local Ray = Ray.new(Tool.Tip.CFrame.p,((mouse.Hit.p-Tool.Tip.CFrame.p)*math.random(0,Spread)).unit*300) --Here. local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) if Hit then if Hit.Parent:FindFirstChild("Humanoid") then Hit.Parent.Humanoid:TakeDamage(20) end end local RayPart = Instance.new("Part",User) RayPart.Name = "RayPart" RayPart.BrickColor = BrickColor.new("Bright red") RayPart.Transparency = 0.5 RayPart.Anchored = true RayPart.CanCollide = false RayPart.TopSurface = Enum.SurfaceType.Smooth RayPart.BottomSurface = Enum.SurfaceType.Smooth RayPart.formFactor = Enum.FormFactor.Custom local Distance = (Position-Tool.Tip.CFrame.p).magnitude RayPart.Size = Vector3.new(0.2,0.2,Distance) RayPart.CFrame = CFrame.new(Position,Tool.Tip.CFrame.p) * CFrame.new(0,0,-Distance/2) game.Debris:AddItem(RayPart,0.1) Tool.Handle.PewPew:Play() end mouse.Button1Down:connect(function() if Automatic then Firing = true repeat Fire() wait(FireRate) until Firing == false else Fire() end end) mouse.Button1Up:connect(function() Firing = false end) end)
MrMcAero |
|
|
| Report Abuse |
|
|
|
| 29 May 2012 03:43 PM |
"Spread" meaning what? Having the bullet move farther from the place you originally clicked as distance increases?
--(Support The Tributes)-{http://www.roblox.com/--place?id=71037485}-- |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 29 May 2012 03:44 PM |
Yea, like if you look at a real gun, it never actually hits where you point at. So, the end point of the bullet has an "Offset", and you can set that offset.
MrMcAero |
|
|
| Report Abuse |
|
|
malachi11
|
  |
| Joined: 07 May 2008 |
| Total Posts: 2420 |
|
|
| 29 May 2012 03:50 PM |
local Ray = Ray.new(Tool.Tip.CFrame.p,((mouse.Hit.p+Vector3.new(math.random(0,Spread),math.random(0,Spread),math.random(0,Spread))-Tool.Tip.CFrame.p).unit*300)
Try that. :P |
|
|
| Report Abuse |
|
|
|
| 29 May 2012 03:51 PM |
--> RayPart.CFrame = CFrame.new(Position,Tool.Tip.CFrame.p) * CFrame.new(0,0,-Distance/2)<--
I think that if you use a math.random() for the CFrame that it's multiplying by, it will most likely create a spread.
|
|
|
| Report Abuse |
|
|
|
| 29 May 2012 03:51 PM |
@Mal: Darn you. :P I had to take out the garbage. :P |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 29 May 2012 03:51 PM |
Testing..
Outcome:
Doesn't even fire.
MrMcAero |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 29 May 2012 03:54 PM |
You were missing a ), but now I get an output:
Players.Player.Backpack.SemiAuto.Shooter:11: bad argument #2 to 'random' (number expected, got nil)
MrMcAero |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 29 May 2012 03:55 PM |
Got it. I forgot to define Spread somehow.
MrMcAero |
|
|
| Report Abuse |
|
|
MrMcAero
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
| |
|