ozza
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 726 |
|
|
| 29 Apr 2012 02:52 PM |
local Tool = script.Parent local User Tool.Equipped:connect(function(mouse) User = Tool.Parent mouse.Button1Down:connect(function() if script.Parent.Ammo.Value > 0 then 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 expl = Instance.new("Explosion") expl.Parent = Workspace expl.Position = Hit.Position if Hit.Parent:FindFirstChild("Humanoid") then Hit.Parent.Humanoid:TakeDamage(30)
end end local RayPart = Instance.new("Part",User) RayPart.Name = "RayPart" RayPart.BrickColor = BrickColor.new("Bright yellow") RayPart.Transparency = 0 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.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) --Move it halfway. game.Debris:AddItem(RayPart,0.1) --Add it to the debris. script.Parent.Ammo.Value = script.Parent.Ammo.Value-1 end
end) end)
So I have this code, which is in my gun, but my question is, for the explosion is there a way to make it spawn DIRECTLY where the ray hit?
- Ozza - |
|
|
| Report Abuse |
|
|
ozza
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 726 |
|
| |
|
grantox
|
  |
| Joined: 26 Nov 2010 |
| Total Posts: 2314 |
|
|
| 29 Apr 2012 04:01 PM |
| Well i don't know about directly where it hit, but you could center it on the brick or piece of terrain it hit. but i don't know didly squat about scripting ;) |
|
|
| Report Abuse |
|
|
ozza
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 726 |
|
|
| 29 Apr 2012 04:13 PM |
| The point is it already does that. |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2012 04:16 PM |
| I guess you could use the ClosestPoint method of the Ray... |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2012 04:17 PM |
wait...
Doesn't the FindPartOnRay method also give you the position? |
|
|
| Report Abuse |
|
|