|
| 15 Oct 2012 05:12 PM |
Sorry for double post but I seemed to have worded this wrong. I'm wondering how to add a spreed effect to my ray casting gun that ive made using the wiki http://wiki.roblox.com/index.php/How_to_Make_a_Raycasting_Lasergun
Code " --Variavles--start local tool = script.Parent local user = nil local debounce = false --Variavles--end
--Main/Functions/Logic--start tool.Equipped:connect(function(mouse) user = tool.Parent mouse.Button1Down:connect(function() if debounce == false then debounce = true for i = 1, 10 do print("lol") wait(0.1)
--make the ray --local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)-- 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) print(mouse.Hit.p) --do damage to humanoid if hit-- local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") if humanoid then humanoid:TakeDamage(30) end --draw the ray local distance = (position - tool.Handle.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = BrickColor.new("Bright yellow") rayPart.Parent = game.Workspace 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 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 wait(0.5) debounce = false end end) end) --Main/Functions/Logic--end"
Thanks in advanced.
|
|
|
| Report Abuse |
|
|
| |
|
poulsen
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 15552 |
|
|
| 15 Oct 2012 06:25 PM |
Sorry, but I'm just a starter, so I didn't understand half of this...
~ I'm making a note here, huge success! C: ~ |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 15 Oct 2012 10:55 PM |
local rayPart = Instance.new("Part", user)
It has to be in character/workspace, you can't just put it in the user, unless user = Character, i wasn't paying attetntion |
|
|
| Report Abuse |
|
|
|
| 15 Oct 2012 10:58 PM |
That's not what I want, I want a spreed effect on the ray
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 15 Oct 2012 11:00 PM |
| use Magnitude and a table to put items near the ray in their, and for each object in table, you do what you need to, then remove it fro table |
|
|
| Report Abuse |
|
|
|
| 15 Oct 2012 11:01 PM |
I don't understand...
I'm trying to change the accuracy of the gun..
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 15 Oct 2012 11:03 PM |
| Change a vector to a math random (cur - 3, cur + 3) where cur is what it shoud be |
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 15 Oct 2012 11:05 PM |
So, the ray position is (X, Y, Z) right?
do
Position = Vector3.new( math.random(X - 3, X + 3), math.random(Y - 3, Y + 3), math.random(Z - 3, Z + 3) )
Or seomthing like that |
|
|
| Report Abuse |
|
|
|
| 15 Oct 2012 11:07 PM |
The problem is
in real life the father out you shoot the less accurate the gun is right? Not with that though.... doesn't matter how far you shoot the gun will always be a little non accurate
|
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 16 Oct 2012 03:39 AM |
| REALLY pokemon!? You freaking removed the 'shake' -.-? Well, i'm not going to help you anymore you idiot. |
|
|
| Report Abuse |
|
|
|
| 16 Oct 2012 08:54 AM |
Yeah cause it's not what i'm looking for...
If you not going to help me then stop posting.
|
|
|
| Report Abuse |
|
|
poulsen
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 15552 |
|
|
| 16 Oct 2012 09:15 AM |
| When I posted that post, I thought I'd help you by bumping it... |
|
|
| Report Abuse |
|
|
|
| 16 Oct 2012 10:28 AM |
I can bump it my self thanks though.
|
|
|
| Report Abuse |
|
|
woot3
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 3599 |
|
|
| 16 Oct 2012 11:32 AM |
Please post the output this provides. What it should be doing but isn't. And make sure that I know roughly where the script is going wrong.
I dislike long scripts. |
|
|
| Report Abuse |
|
|
|
| 16 Oct 2012 11:57 AM |
Dude if you read the thread there's no error i'm wondering how to add a spread effect to the ray
|
|
|
| Report Abuse |
|
|
woot3
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 3599 |
|
|
| 16 Oct 2012 12:02 PM |
By spread, I am guessing you mean Accuracy?
Spread = 0.01 --For every stud the bullet travels, the more it goes off Distance = (StartOfRayPosition-CurrentRayEndPosition).magnitude --Get the distance from the start of the ray until the end Offset = Vector3.new(math.random(-(Distance*Spread),Distance*Spread),math.random(-(Distance*Spread),Distance*Spread),math.random(-(Distance*Spread),Distance*Spread)) --Calculate the offset due to spread RayEndPosition = CurrentRayEndPosition+Offset --Apply the Offset for the new end position
Hope this helps. |
|
|
| Report Abuse |
|
|
|
| 16 Oct 2012 12:17 PM |
| But the problem is if you shoot really far it's still the same Accuracy |
|
|
| Report Abuse |
|
|
woot3
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 3599 |
|
|
| 16 Oct 2012 12:25 PM |
Nope, what I have done, is something fairly smart. To be accurate, each of the math.randoms needs to be between -2 and 2. The further you get away the higher and lower the bounds get. Meaning it's less likely to shoot accurately.
For instance.
If you are 20 studs from the player, and the spread is set to 0.01 then it will hit within 0.2 studs of that player.
However, if you were 500 studs from that player, and the spread was 0.01 it would hit within 5 studs of that player.
20 studs will hit them. 500 studs can hit them, but has a 60% chance of not hitting them.
You can make the spread higher to reduce accuracy. Setting it to 0.1 is something that I recommend.
I also suggest splitting each section by 100, to allow for decimals and not such a grid based shot. I will post that below
Spread = 0.1 Distance = (StartOfRayPosition-CurrentRayEndPosition).magnitude Offset = Vector3.new(math.random(-(Distance*Spread*100),Distance*Spread*100)/100,math.random(-(Distance*Spread*100),Distance*Spread*100)/100,math.random(-(Distance*Spread*100),Distance*Spread*100)/100) RayEndPosition = CurrentRayEndPosition+Offset |
|
|
| Report Abuse |
|
|
|
| 16 Oct 2012 12:30 PM |
I don't really understand what you are trying to do here.......
:s |
|
|
| Report Abuse |
|
|