#Hello o3o
1 messages · Page 1 of 1 (latest)
For unity, I have a series of rooms (red boxes) sitting over an (unimportant to this problem) blue plane.
These rooms start as primitive 1,1,1 cubes at position Vector.Zero relative to the parent object GenerationCage which simply contains all the rooms for us and the script in question.
I iteratively walk through the rooms and scale, then position them in locations I prefer. I store this room GameObject in a list of rooms to keep track of the rooms added.
The problem:
For each room, I aim to find if that room is simply colliding with any other room. This could be collisions, location tracking, etc. Literally anything, whatever is simplest and/or preferably, fastest.
If a room is colliding with ANY other room (not itself but overlapping with another room), then I would immediately move this room Vector.UP; then move to the next room in the list.
I have been exploring a few different options, all of which have been unsuccessful or run waaay too long and are less efficient than necessary.
Collision checking seems to be difficult to get done, and waiting for fixedupdates for Physics is not ideal as the player and game will never interact with these objects during creation, this is simply a set up script.
The intended result for example in the image above:
-
The top left and bottom left rooms will simply remain.
-
The three overlapping rooms will depending on their placement in the list elevate upward.
Start: (X being a physical room representation)...
y=2 | ............X
y=1 | ......X......
y=0 | X...........
So while they overlapped prior, these rooms are now on their own Y vertical level from each other.
You need to call Physics.SyncTransforms() after moving objects around
Otherwise, physics queries will be using the old state of the eworld
Ah that would make sense, since I put some debug prints that would just act as if every room was overlapping each other at Vector.Zero where I instantiate them initially
Also, if these rooms are just axis-aligned boxes, you can create Bounds objects and see if they touch
They are axis aligned, then if they are found to be overlapping at all they are moved up, then once every room on level 0 is no longer overlapping the process moves to y=1 or level 1 to do the process over again, moving things up one by one.
Phase 2 and phase 3 I manually did to be more exaggerated for the example
Well I guess they'd end at phase 2 since no more overlaps, but the idea is there :p
I will investigate using bounds again after I sync the transforms across the objects
I guess a main question I have here is do I really have to use RigidBodies?
I'm not familiar enough to know if that would save me time
This is a room when created
One annoying thing is that 3D physics lacks a way to ask if a collider is touching any other colliders
I weep
Rigidbodies would be needed if you wanted to receive collision messages at runtime
I wound up writing a bit of code to turn a box collider into a "box shape" -- position, extents, rotation
So attach a RB at the creation of the instance, then I can sync the transforms after I scale and position the rooms, then I refer to collision checking...
You did mention using AABB bounds instead, would these require rigidbodies as well? They sound easier for this case if not
I can then use that to do a CheckBox query
Rigidbodies don't make sense here -- you just want to manually query if a room is overlapping anything else
So the bounds method would likely work best and then move the aligned axis Y up 1 increment until I run through without overlaps?
Transform boxTransform = boxCollider.transform;
Vector3 center = boxTransform.TransformPoint(boxCollider.center);
Vector3 worldExtents = Vector3.Scale(boxCollider.size / 2, boxTransform.lossyScale);
Quaternion rotation = boxTransform.rotation;
if (Physics.CheckBox(center, worldExtents, rotation)) {
// ...
}
One gotcha: this is guaranteed to find your own collider
In my case, I have separate layers for the "probes" and for the things the probes are looking for
yeah I ran into that as well