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: Efficent part to part distance detection

Previous Thread :: Next Thread 
MidasTouched is not online. MidasTouched
Joined: 02 Dec 2016
Total Posts: 242
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
13 Jun 2017 12:31 AM
either way it will have to render on every physics frame to be accurate*
Report Abuse
MidasTouched is not online. MidasTouched
Joined: 02 Dec 2016
Total Posts: 242
13 Jun 2017 12:34 AM
Wait can you please explain that more in depth?
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
MidasTouched is not online. MidasTouched
Joined: 02 Dec 2016
Total Posts: 242
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
13 Jun 2017 01:16 AM
i keep typing strangely for some reason just try to make sense of it lol
Report Abuse
OzzyFin is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
MidasTouched is not online. MidasTouched
Joined: 02 Dec 2016
Total Posts: 242
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 is not online. 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
MidasTouched is not online. MidasTouched
Joined: 02 Dec 2016
Total Posts: 242
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
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