Adam's Lair Forum

game development and casual madness
It is currently 2018/04/19, 23:09

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Find Components in area
PostPosted: 2017/11/07, 07:19 
Junior Member
Junior Member

Joined: 2016/01/09, 22:52
Posts: 35
Role: Hobbyist
I am trying to find all the components in an certain area in my Scene. I expect the GameObjects to have RigidBodies attached to them so I am trying to use the static RigidBody querying functions. The functions which return lists of bodies/shapes all seem to be depreciated and suggest using the ones which require passing a list bodies/shapes. Those functions return boolean values and not a specific object. Is there a suggested way of searching for a set of GameObjects in an area?


Top
 Profile  
 
PostPosted: 2017/11/07, 22:04 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 859
Location: Italy
Role: Hobbyist
Depending on the grade of precision you need, I'd say that the simplest way would be to get all RigidBodies in the Scene (Scene.GetComponents<RigidBody>) and from that check if their relative Transform.Pos is inside your area of interest.

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
PostPosted: 2017/11/08, 02:45 
Junior Member
Junior Member

Joined: 2016/01/09, 22:52
Posts: 35
Role: Hobbyist
OK. I was hoping there would be some way of taking advantage of the physics engine's quad tree for faster querying but that should work fine.


Top
 Profile  
 
PostPosted: 2017/11/08, 20:24 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2042
Location: Germany
Role: Professional
zakila wrote:
OK. I was hoping there would be some way of taking advantage of the physics engine's quad tree for faster querying but that should work fine.


Actually, you could also use RigidBody.QueryRectGlobal to do exactly that :) It's a broadphase check optimized for speed, so you may get bodies that are not actually in that area, but you will never miss a body that is.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
PostPosted: 2017/11/09, 19:50 
Junior Member
Junior Member

Joined: 2016/01/09, 22:52
Posts: 35
Role: Hobbyist
Wow I did not read the documentation correctly at all. I thought the list you passed to the querying function was the bodies to search through, not a list that gets filled with the results of the query. I will use the QueryRectGlobal function.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group