generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to detect which brick is closer to your character

Previous Thread :: Next Thread 
Kilometerz is not online. Kilometerz
Joined: 20 Sep 2012
Total Posts: 2666
08 Aug 2014 04:45 PM
Possible I think
Report Abuse
Vescatur is not online. Vescatur
Joined: 18 Feb 2012
Total Posts: 3426
08 Aug 2014 04:48 PM
More info please
Report Abuse
dragonkeeper467 is not online. dragonkeeper467
Joined: 24 Jan 2011
Total Posts: 472
08 Aug 2014 04:50 PM
use magnitude
Report Abuse
Kilometerz is not online. Kilometerz
Joined: 20 Sep 2012
Total Posts: 2666
08 Aug 2014 04:50 PM
Well I want to make it to where if you "black out" you teleport to the nearest hospital.
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
08 Aug 2014 04:50 PM
You could probably use those codes in zombies where it detects the nearest character. You could possibly do this by editing when the zombie detects a humanoid where instead you can make it so if the player detects bricks with values inside them so check if they are the 'brick' then it will return a function.
Report Abuse
Vescatur is not online. Vescatur
Joined: 18 Feb 2012
Total Posts: 3426
08 Aug 2014 04:52 PM
I'd personally use a localscript and do a DistanceFromCharacter() event when they die to see which one is closer.
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
08 Aug 2014 04:59 PM
@Ves

I learnt something from j00 now. I never heard DistanceFromCharacter() before. :/
Report Abuse
Ragnarope is not online. Ragnarope
Joined: 12 Jul 2014
Total Posts: 3852
08 Aug 2014 05:06 PM
(Character.Torso.Position - brick.Position).magnitude



-ForeverDev [ R$14,435 / 2,500,000 ]
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
08 Aug 2014 05:08 PM
@rag

Looks like you used that code from this source: http://www.roblox.com/Forum/ShowPost.aspx?PostID=121001053

(Scroll down to find it)
Report Abuse
Ragnarope is not online. Ragnarope
Joined: 12 Jul 2014
Total Posts: 3852
08 Aug 2014 05:14 PM
I didn't, that's just how you would do it.

You make a function that takes a table parameter, then pass all the bricks into the function as a table, and the closest brick would be returned



function getCloseBrick(bricks, player)
if not player.Character then return false end
local pos = player.Character.Torso.Position
local nearest;
for i, v in pairs(bricks) do
if not nearest then
nearest = (pos - v.Position).magnitude
elseif (pos - v.Postion).magnitude < nearest then
nearest = (pos - v.Position).magnitude
end
end
return nearest
end

--you could then pass the children of a model into the function, with the player

local closestBrick = getCloseBrick(Workspace["model name"]:GetChildren(), game.Players.Ragnarope)


-ForeverDev [ R$14,435 / 2,500,000 ]
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image