yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 08 Mar 2015 11:50 AM |
| Is there a way i can detect if there is a model within x studs of the character? |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2015 11:58 AM |
Magnitude. http://wiki.roblox.com/index.php?title=Magnitude
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 08 Mar 2015 12:16 PM |
| Ok, i gert that but how can i detect wether there is another mdoel within a certain magnitude? |
|
|
| Report Abuse |
|
|
yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 08 Mar 2015 12:22 PM |
| COuld i create a table of all the characters in the workspace then say while true do and constantly be checking to see if the magnitude of another character is less than 200? |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2015 12:24 PM |
local part=workspace.Part for _,v in pairs(game.Players:GetChildren())do if v.Character:FindFirstChild('Torso') then if (v.Character.Torso.Position-part.Position).Magnitude < 200 then
end end end |
|
|
| Report Abuse |
|
|
yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 08 Mar 2015 12:26 PM |
How can i then print that magnitude? i tried
local part=workspace.Part for _,v in pairs(game.Players:GetChildren())do if v.Character:FindFirstChild('Torso') then if (v.Character.Torso.Position-part.Position).Magnitude < 200 then print(v.Character.Torso.Position-part.Position).Magnitude) end end end
|
|
|
| Report Abuse |
|
|
yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 08 Mar 2015 12:28 PM |
| Or more to the point, how could i draw a raycast between the part and the char that went near it |
|
|
| Report Abuse |
|
|
|
| 08 Mar 2015 12:29 PM |
| You have to constantly search the workspace and run the function. |
|
|
| Report Abuse |
|
|
yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 08 Mar 2015 12:30 PM |
| Ok i have a script which displays the magniute, btu now how can i draw a rtyacast? |
|
|
| Report Abuse |
|
|
yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 08 Mar 2015 12:46 PM |
Done
--while wait(3) do --local part1 = script.Parent --local part2 = script.Parent.Parent.Part2
--local magnitude = (part1.Position - part2.Position).magnitude --if magnitude < 200 then ----print(magnitude) --end --end
local part=workspace.Part
while wait(1) do for _,v in pairs(game.Players:GetChildren())do if v.Character:FindFirstChild('Torso') then local magnitude = v.Character.Torso.Position-part.Position if magnitude.Magnitude < 200 then print(magnitude.Magnitude) local ray = Ray.new(part.Position, (v.Character.Torso.Position - part.Position)) local hit, position = game.Workspace:FindPartOnRay(ray, part)
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") if humanoid then humanoid:TakeDamage(10) end
local distance = (position - part.Position).magnitude local rayPart = Instance.new("Part", game.Workspace) 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 rayPart.Size = Vector3.new(0.2, 0.2, distance) rayPart.CFrame = CFrame.new(position,part.Position) * CFrame.new(0, 0, -distance/2)
--add it to debris so it disappears after 0.1 seconds game.Debris:AddItem(rayPart, 5)
end end end end
|
|
|
| Report Abuse |
|
|