|
| 13 Jun 2017 12:25 AM |
| Let's say I have two parts and I want to check if they're within a certain distance from each other. Well that's all good and easy, just do a simple while loop with .magnitude. Alternatively, I could make a cylinder acting like a radius with a .tocuhed event. But what if I have many of these parts that detect other parts? It becomes inefficent really quickly to have each part have a script looping through all the the other parts, checking if all the other parts are within the radius. With a Touched event, the events would fire so often for all the parts I imagine it would lag. Does anyone have a solution to make this efficent, like some sort of "inDistance" event or something weird? Note that it has to be a radius, or else I'd be using Region3 |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 12:30 AM |
| well either way it would always have to be ran every frame physics has been rendered to be detected so |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 12:31 AM |
| either way it will have to render on every physics frame to be accurate* |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 12:34 AM |
| Wait can you please explain that more in depth? |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 12:37 AM |
well either the engine will have to calculate distances on every physics frame and then fire the event or u will have to do it in lua so it doesnt really make much of a difference aside from possible poor coding and memory increase and there is also a spherical region3 in roblox libraries |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 12:38 AM |
| and the touched event shouldnt lag if u r checking to make sure things have specific cooldowns so that they arent doing specific things 100% of the time |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 12:41 AM |
| I see what you're saying. I suppose a while loop is the way to go then, as I can control how often it updates. I'll look into the spherical region3, I tried finding something like it before but didn't manage it. Thanks for helping me out. |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 01:15 AM |
| and no u most likely should not be using a while loop and instead should instead bind the function to heartbeat, stepped, or renderstepped (depending on which host and method) as it fires more accurately per tick |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 01:16 AM |
| i keep typing strangely for some reason just try to make sense of it lol |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 13 Jun 2017 01:21 AM |
Just test all the solutions you can come up with and look at the script performance.
People often tend to worry about some kind of lag due to a lot of events firing/iterations way too much. It is usually not that big of a deal but obviously depends on what you're doing. Find the best option then optimize it if needed. |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 01:24 AM |
| ive heard of there being a spherical region3 but i cant find it so ya i would recommend touched or checking magnitude of parts within a specific region |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 01:29 AM |
| Don't wanna do something that updates too often is the thing. If I have about 150 different parts all having radius detection, it could get laggy if I bind it on renderstepped. I'll just try both and see what works best. Thanks for the suggestions. |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 13 Jun 2017 04:24 AM |
I've used raycasting, shooting out at several angles in a circle.
worked for me so it didn't have to loop through, and have it ignore everything except the objects i wanted it to detect
main disadvantage is that you can't cover every angle, so there is a possibility of missing it, unless the detector rotates |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2017 10:56 AM |
| Yeah I've thought of that, but most of my detecting objects are moving and I don't believe rays move with objects. Plus I think that would be just like having the radius and doing :GetTouchingParts() |
|
|
| Report Abuse |
|
|