So, bit of a different question here, how would I go about to find the closest physical object to a certain physical object? Is there a method such as physicsobject1.getClosest(RigidBodyControl.class) or similar? That would be awesome! Any help or similar method appreciated
I don’t know about a straight way to find that out.
There might be a more clever solution than this, but you could just loop through your objects, find the nearest (via the .distance() of their locations) and check whether it has RigidBodyControl (or whatever you use) or not.
Sorry if you thought of that already and search for a smarter approach though…
@benkibitzer said: I don't know about a straight way to find that out. There might be a more clever solution than this, but you could just loop through your objects, find the nearest (via the .distance() of their locations) and check whether it has RigidBodyControl (or whatever you use) or not. Sorry if you thought of that already and search for a smarter approach though...
I actually thought about that, but I was thinking that such a loop may become heavy both to write (adding all objects to some sort of list) and to actually do the loop on if in Update… I also have some objects in other classes, public and not, so it might just become a bit tricky to actually make it work! Last resort perhaps…
adding all objects to some sort of listNo creation of a list needed is it? Your (root)node has that list already, just remember the one object you looped through and check if the next is nearer (and if so, remember that one). But yeah, you should wait for one of the pros to show up and share some thoughts :) .
@benkibitzer said: Your (root)node has that list already
Of course! I forgot that …
note that then you’ll compare only the distance between centers, not between “sides”. And i think that there is no easy way to get the real distance, as objects can have very strange shapes. But if you need something closer to the “side” distance, you can just get the boundingvolume and calculate the distance between center of volumes and remove the extends of both volume from the result. Something like that should give you a nice enough result most of times.
Maybe you could do a few sweepTests in the direction(s) you are interested in.
I actually seem to have nailed down the problem… I added physicslisteners and everything, and now the ghost control actually notices when it is colliding with the room and when it is not! However, it only really notices when it is outside the room, as it reckons that just being inside the shape of the room (it’s a RigidBodyControl btw) will count as a collision. If I “leave” the room with the ghostControl (by pushing it out of the wall) it realises it is not intersecting and does all appropriate code! Any ideas how this could be fixed, or if I should change the type of physics from RBC?
The model was done in blender btw, and the debug screen only shows blue lines etc where the walls actually are… not inside the room!