#Hello o3o

1 messages · Page 1 of 1 (latest)

serene elk
#

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.

hexed bane
#

You need to call Physics.SyncTransforms() after moving objects around

#

Otherwise, physics queries will be using the old state of the eworld

serene elk
#

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

hexed bane
#

Also, if these rooms are just axis-aligned boxes, you can create Bounds objects and see if they touch

serene elk
#

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

hexed bane
#

One annoying thing is that 3D physics lacks a way to ask if a collider is touching any other colliders

serene elk
#

I weep

hexed bane
hexed bane
serene elk
hexed bane
#

I can then use that to do a CheckBox query

hexed bane
serene elk
#

So the bounds method would likely work best and then move the aligned axis Y up 1 increment until I run through without overlaps?

hexed bane
#
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

serene elk
#

yeah I ran into that as well

hexed bane
#

so that's not an issue

#

In this case, you'd need to either use an OverlapBoxAll query and ignore your own collider

#

or you'd need to disable the collider, sync transforms(?), and then test

#

i'm pretty sure you have to call SyncTransforms after disabling a collider