phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 04 Sep 2015 05:31 PM |
I posted this in Game Design, and I was told to go here.
I'm making a gun that uses raycast to detect hits. It's programmed to do extra damage for hits to the head, but it doesn't always detect it. In fact, when I hooked it up to a function that printed whatever part the gun hit, it detected NOTHING when it hits the head and does no damage. How do I fix this?
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
|
| 04 Sep 2015 05:32 PM |
post code
also, are hats blocking it? are you ignoring hats when casting the ray? |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 04 Sep 2015 05:33 PM |
@Long
It's definitely the hats. Is there a way to ignore hats? Sorry, I'm a novice to scripting.
Anyways, here's the code:
local tool = script.Parent local user
tool.Equipped:connect(function(mouse) user = tool.Parent
mouse.Button1Down:connect(function() local ray = Ray.new(tool.AimPart.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user)
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") if humanoid then print(hit.Name) if hit.Name == "Head" or hit.Parent.className == "Hat" then humanoid:TakeDamage(100) else humanoid:TakeDamage(30) end end
-- Settings local distance = (position - tool.AimPart.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = BrickColor.new("Really blue") 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.AimPart.CFrame.p) * CFrame.new(0, 0, -distance/2) game.Debris:AddItem(rayPart, 0.1) end) end)
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
| |
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 05 Sep 2015 10:05 AM |
straight off the wiki
➳Lɪᴛᴀʟᴇʟᴀ ɪs ᴍʏ ɴᴀᴍᴇ, Lᴜᴀ ɪs ᴍʏ ɢᴀᴍᴇツ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
| |
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 05 Sep 2015 12:42 PM |
Bump1
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 05 Sep 2015 05:07 PM |
Bump2
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 05 Sep 2015 05:13 PM |
| hit.Name == "Head" or hit.Name == "Handle" |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2015 05:16 PM |
sry, I didn't read the code, am a lil in a hurry...
local hit, pos = game:FindPartOnRay(Ray, Ignore) --lets just say it's like that if hit.Parent:IsA('Hat') then hum = script.Parent.Parent:FindFirstChild('Humanoid') else hum = script.Parent:FindFirstChild('Humanoid') --stuff end
"My Life is going Good... but..." |
|
|
| Report Abuse |
|
|
louiskk
|
  |
| Joined: 31 Dec 2008 |
| Total Posts: 228 |
|
|
| 05 Sep 2015 05:19 PM |
| I'm guessing you might want to ignore the tool parts as well as the hat, in which case you could use FindPartOnRayWithIgnoreList which accepts a table instead of a single ignore value. |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 05 Sep 2015 05:37 PM |
@louis
So how would I set up the "Ignore" table? I looked up the function you mentioned on the Wiki, but the documentation was very sparse.
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 05 Sep 2015 06:23 PM |
Bump3
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 05 Sep 2015 08:13 PM |
Bump4
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 05 Sep 2015 08:13 PM |
make sure the part you are shooting from is very very small
otherwise it will aim to the left
i know from experience
➳Lɪᴛᴀʟᴇʟᴀ ɪs ᴍʏ ɴᴀᴍᴇ, Lᴜᴀ ɪs ᴍʏ ɢᴀᴍᴇツ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 05 Sep 2015 08:16 PM |
@lit
Thanks for the advice, but it didn't really solve my problem.
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2015 08:43 PM |
@phoniex Solved it local tool = script.Parent local user
tool.Equipped:connect(function(mouse) user = tool.Parent
mouse.Button1Down:connect(function() local ray = Ray.new(tool.AimPart.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user)
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") if humanoid then print(hit.Name) if hit.Name == "Head" then humanoid:TakeDamage(100) elseif hit.className == "Hat" then hit:Destroy() else humanoid:TakeDamage(30) end end
-- Settings local distance = (position - tool.AimPart.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = BrickColor.new("Really blue") 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.AimPart.CFrame.p) * CFrame.new(0, 0, -distance/2) game.Debris:AddItem(rayPart, 0.1) end) end)
|
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 06 Sep 2015 11:40 AM |
@Chris
No, that didn't solve the problem.
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 01:05 PM |
@Phoniex
I think this might be it, i made a mistake.
@phoniex Solved it local tool = script.Parent local user
tool.Equipped:connect(function(mouse) user = tool.Parent
mouse.Button1Down:connect(function() local ray = Ray.new(tool.AimPart.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user)
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") if humanoid then print(hit.Name) if hit.Name == "Head" or hit.className=="Hat" then humanoid:TakeDamage(100) else humanoid:TakeDamage(30) end end
-- Settings local distance = (position - tool.AimPart.CFrame.p).magnitude local rayPart = Instance.new("Part", user) rayPart.Name = "RayPart" rayPart.BrickColor = BrickColor.new("Really blue") 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.AimPart.CFrame.p) * CFrame.new(0, 0, -distance/2) game.Debris:AddItem(rayPart, 0.1) end) end) |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 06 Sep 2015 02:51 PM |
@chris
Still not fixed.
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 06 Sep 2015 03:34 PM |
BUmp
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 07 Sep 2015 04:06 PM |
BUMP
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 07 Sep 2015 04:54 PM |
B1
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|
|
| 07 Sep 2015 04:58 PM |
Wait raycasting ignore lists accepts tables!!??
Why didn't anyone tell me... |
|
|
| Report Abuse |
|
|
phoniex
|
  |
| Joined: 03 Feb 2008 |
| Total Posts: 34985 |
|
|
| 07 Sep 2015 05:00 PM |
@Illegally
I'm still not sure how the ignore list works. Can you explain?
~Cookies need love like everything does.~ |
|
|
| Report Abuse |
|
|