T0XZ
|
  |
| Joined: 22 Sep 2012 |
| Total Posts: 260 |
|
|
| 10 Jan 2017 06:45 PM |
| Is anyone aware of a better way to have an NPC start following you when you're within a certain distance of the Torso. From all the follow scripts I've seen it uses a While True Do and searches the workspace for a torso every 1 second or whatever the time in the While True Do is. This obviously isn't effective because if scans workspace every second anyone know of a better method? |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 10 Jan 2017 06:46 PM |
A large block around it, .touched.
|
|
|
| Report Abuse |
|
|
T0XZ
|
  |
| Joined: 22 Sep 2012 |
| Total Posts: 260 |
|
|
| 10 Jan 2017 06:48 PM |
| so just weld a big brick to the NPC's Torso with CanCollide off? @Wow |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 10 Jan 2017 06:52 PM |
Yeah, that's probably the least resource intensive method even though it appears to be basic/nooby.
|
|
|
| Report Abuse |
|
|
T0XZ
|
  |
| Joined: 22 Sep 2012 |
| Total Posts: 260 |
|
| |
|
|
| 10 Jan 2017 06:55 PM |
| I think that's pretty resource intensive because the Touched event would be firing hundreds of times per second. |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 10 Jan 2017 06:56 PM |
It just sounds stupid when you say it :P
A lot more effective and easier to implement than 1. storing table of positions and sorting it to see how close/far 2. .magnitude with while wait loops
Make the function disconnect when it has a target, that's the only time it would lag (ie hitting every brick within 10 studs of the npc or something)
|
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 06:58 PM |
I think it would be better to just search all the players and compare torso distances
If you are really concerned about efficiency you can check player's distances who are close (maybe like the closest 3) more often and then the players who are far you can check periodically (depending on their distance and the time it would take them to get close) |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 10 Jan 2017 06:59 PM |
Why would .touched be firing hundreds of times a second?
How is it not better than sorting the details of every NPC and every player's position and distance between eachother?
|
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 07:02 PM |
| I would suggest some kind of spatial partitioning data structure. A.K.A region3s. Or if you wanted to make your own implementation of KD Trees that would be even better. |
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 07:02 PM |
"Why would .touched be firing hundreds of times a second?"
cause if the dude is walking through a map depending on the size of the brick and the detail of the map, it could cause Touched to be fired many times every frame
i.e. say the box gets in range with a brick wall consisting of 200 parts, the touched event will fire 200 times at least and probably more because touched would probably fire every time the NPC moved
a loop would only need to run code every second or so, and not that much code at that |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 10 Jan 2017 07:05 PM |
Touched is a brick surrounding NPC, not player. I assumed he would be stationary, when he moves/has a target simply disconnect the touched function and restart it once target is lost.
Alternatively, if npc is moving, you can check region 3 every 3 seconds or so.
|
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 07:06 PM |
Oh, that makes sense if the NPC is completely stationery
I was assuming that it would pace mindlessly and follow you once you are in range |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 10 Jan 2017 07:07 PM |
Yeah, your statement totally makes sense if they're both moving.
If that was true than I would check magnitude of players position every few seconds vs his position
|
|
|
| Report Abuse |
|
|