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.
You need to use magnitude
to 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!
Use RayCasting