Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Measuring Range in Roblox? No result online! Need help!

Asked by 7 years ago

I'm trying to measure a range for NPC's like any other game than the NPC Will fight/chase after the other NPC or player. But first, I have to learn how to measure range in ROBLOX.

Now I know 1 kind of range is Studs but I have no idea on that because this may be the first time working with that.

That other thing I could do is create a circular part under the NPC and when someone touches the circular party the NPC will chase after them.

Now that IS a way to do it but there must be a more efficient and easier way to do it or else I would have to spam those all over the place and the game eventually lag.

Any feed back, help support is appreciated. Thank you.

I will also accept links to explanations as feedback and support.

Sorry, this sounds like a script request but I had no results through online searches and videos nor the Roblox Wiki.

2 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

You need to use magnitudeto accomplish that. Heres an example:

local camera = game.Workspace.CurrentCamera
local part = workspace.SomePart --Locate your part here
local studsAway = 18 --set how many studs you the player needs to be in range of
game:GetService("RunService").RenderStepped:connect(function()
    if (camera.CoordinateFrame.p - part.Position).magnitude < studsAway then 
--do something
print("hey")
    end
end)

I'm pretty sure this needs to be in a LocalScript though. Please accept answer if this helped though!

0
But i need to do something like if someone is in a certain range of studs then activate my code. How? BlackOrange3343 2676 — 7y
0
I got it. PyccknnXakep 1225 — 7y
0
Just updated my question for you. PyccknnXakep 1225 — 7y
0
Thanks BlackOrange3343 2676 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

Use RayCasting

0
Thats gonna take a lotta rays to go a whole 360 around the character. hiimgoodpack 2009 — 7y
0
No. not really. Void_Frost 571 — 7y

Answer this question