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 » Scripters
Home Search
 

Re: More efficient ways to search for nearby players?

Previous Thread :: Next Thread 
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
26 May 2014 07:23 AM
I was not sure wether to post this thread in this subforum or not, but I figured I might get a better discussion going here than I'd get in Scripting Helpers. So here it goes.

With the AI in my current game I am using a for loop, checking every single players position relative to the mob to see if the player is close enough. As you can imagine, this is extremely processing intensive once you have 50+ mobs and over 20 players, sometimes concurrently. That is why I am now looking for alternative ways to search for nearby players for my mob AI.

My question is therefore; is there any smarter/better/less processing intensive way to search for nearby objects/players? And how would I implement that particular method of searching?
Thanks in advance. :)

~The herp lerped a derp~
Report Abuse
Fluffmiceter is not online. Fluffmiceter
Joined: 28 Jan 2012
Total Posts: 6931
26 May 2014 07:28 AM
Sending out rays in every direction? It might not be efficient, but it can create more realistic humanoids WITHOUT EYES ON THE BACK OF THEIR HEADS -SERIOUSLY

All basic AI's on ROBLOX are either from the Arachnid family, or iguanas with hidden eyes.
Report Abuse
Fluffmiceter is not online. Fluffmiceter
Joined: 28 Jan 2012
Total Posts: 6931
26 May 2014 07:29 AM
*rays in the direction of the AI's lookvector (some rays slightly to the side to increase field view)
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
26 May 2014 07:36 AM
Here's an interesting thought I had:

You could have a giant invisible sphere welded to the mob, connected with a .Touched event. That event will then check for a player, and if the object touched is a player, add the player to the current target list(table). This would simulate the for loop checking with magnitude, but in a more efficient way since it'd only check when the player actually already is close enough. And then of course, a .TouchEnded event to remove the player from the table of targets.

This would probably be highly efficient, since it's a method that makes the AI able to only be activated upon request(touching the sphere).

BUT, I could also imagine a heap of issues using this method, with pretty much every issue concerning .Touched/.TouchEnded events and the way ROBLOX handles them. What are your thoughts on this?

~The herp lerped a derp~
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
26 May 2014 07:41 AM
You are looking for spatial partitioning.

Split up the world into a grid, and place all players in the grid cells according to their position.

When you need to find nearby players, only look at the grid cells around the mob.

It doesnt matter whether there are 10 or 100000 players in the world if they are not in the grid cells that surround the mob, since you only consider the players in them.

The size of the grid cells should be such that its not too small (or youll have to go through a lot of grid cells to find all potential players near your mob, and itll take more memory to store the grid) and not too big (or youll get a lot of 'potentially nearby' players that actually are not nearby)
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
26 May 2014 07:42 AM
And roblox also has the workspace methods for finding parts in a 3D region.

If the mobs dont have that big range this might be easier to use. Youd just find all parts in range, and iterate over them to see if any belong to a player.
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
26 May 2014 07:46 AM
Could you name the methods or link me to a wiki page? :)

~The herp lerped a derp~
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
26 May 2014 07:50 AM
its under the 'workspace' wiki page

i think its called findPartsInRegion3


It would be more efficient and flexible to use the grid approach though.
Report Abuse
morash is not online. morash
Joined: 22 May 2010
Total Posts: 5834
26 May 2014 03:18 PM
Player:DistanceFromPoint(mob.Position) could also be beneficial.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 03:23 PM
DistanceFromChracater*
Report Abuse
EchoReaper is not online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
26 May 2014 03:25 PM
"And roblox also has the workspace methods for finding parts in a 3D region."

The players would automatically be cut out if there were > 100 parts in the region :/
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
26 May 2014 03:26 PM
Comparing the distance to 20 players is NOT expensive.

I just benchmarked it.

Finding the nearest among 20 parts 100 times took me 0.02 seconds.

You are optimizing the wrong thing.
Report Abuse
TheLuaWeaver is not online. TheLuaWeaver
Joined: 09 Feb 2010
Total Posts: 1504
26 May 2014 04:04 PM
Although to add onto Taslem's statement, depending on how many things you're looking for, you should use spatial partitioning as mentioned by Radio.
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
26 May 2014 05:44 PM
Yes, but in the case that filiptibell posted, any such system would almost surely make it *slower* because even with 100 players you're still not looking at an expensive computation by doing it immediately.

Any lookup scheme will not make a noticeable speed increase at this size (n < 100).

Optimizing things like frequency of lookup (not every frame) is where you can save. Algorithmically, O(n) is fine when n is as small as you can count on your digits. .02ms is NOT something that needs to be optimized for a game.
Report Abuse
ScripterJohn13 is not online. ScripterJohn13
Joined: 01 Jan 2010
Total Posts: 5658
27 May 2014 10:21 AM
One way I optemized zombies in places before was to instead of every zombie having a script, why not control all zombies from one script? It allows easier updating, less threads will be ran as every script+every event connection = a thread, I believe. So if you remove all scripts but one you already reduced the number of scripts to be processed and now you don't have to bother with plugins to update all the zombies when you can just update one script. Zombies would use StringValues, intValues, etc to identify them.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
27 May 2014 12:36 PM
Yeah you can just bump the update rate to once every 5 seconds while the zombie isnt near any players...
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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