Multiple interior collision spaces/pocket collision dimensions.
My game has a number of planets and ships, all of which have their own interior 'spaces' that the players are teleported to when they board the object. Multiple players and objects can exist in their own interiors at the same time, so I need to simulate all of the spaces simultaneously, without having them interact with each other. Ideally, the physics engine should also know that bodies in different spaces should ignore each other.
Does unity support multiple 'spaces' within the same scene? As in, multiple units could exist at the same world coordinates, without colliding with each other? And with only the cameras that exist in that space rendering objects within its frustrum?
I have looked at using multiple collision layers to represent multiple spaces, but they seem to be capped at 30 layers. If unlimited collision layers were possible, this would solve my problem.
My current solution is to place all of the interior spaces at (0, 0, 0) , and then separate them from each other by spreading them out along the z-layer so that entities in different interior spaces cannot collide with each other. I also place the Sun at (0, 0, 0), and make it surround interior space. The Sun is bigger than the maximum number of interiors * the max width of an interior. That way, objects in world space cannot interact with objects in interior space.
Is there a simpler, more elegant solution to having multiple 'pocket dimensions?' Carving off a chunk of world space to place the interiors seems like a bit of a hack.
$$anonymous$$ultiple players and objects can exist in their own interiors at the same time, so I need to simulate all of the spaces simultaneously, without having them interact with each other.
It's even easier if you don't want them to interact with each other. Simply have your individual rooms, that are the interior spaces, and add everything that belongs there as a child of it. You don't need to have all of them at the same coordinates, do you?
The Sun is bigger than the maximum number of interiors the max width of an interior. That way, objects in world space cannot interact with objects in interior space.*
That seems fine as your planets (or suns) don't actually have a surface to go on. You could just leave them there.
Carving off a chunk of world space to place the interiors seems like a bit of a hack. That's how it's done. You could also make every interior a new scene, but that wouldn't really change anything except maybe loading times when switching.
I read in your comment on Oribows answer: Each interior space has it's own set of coordinates, centered on x,y = 0,0. The reason for this is this is to avoid moving levels colliding with moving units, which often causes unreliable collision
I thought those interior spaces are fixed inside the sun object? why are they moving?
I've gone with arranging the interiors in their own regions in world space, inaccessible other than by entering the relevant ship.
In regards to your last paragraph, the interiors are not moving. It would be nice if they could move, because then I wouldn't have a problem. I could just have the interior levels positioned inside the ships that they belong to. Having stationary interiors that the players teleport to was my solution to the problem of emulating a moving ship interior.
Oh, ok, so you want to actually see the outside from within the ship? Like Subnautica? But on a much larger scale(having crew members walking around)?
I'm no expert on physically correct simulation of child-systems within other systems.
But I got a cheap (but working perfectly) trick to propose: Have the interiors stationary, and use render target texturs with cameras placed on the window positions of the ship objects. When you are inside a ship, you would actually be in the stationary object, but the window textures render what the cameras mounted to the outisde of the real ship see.
It might help in your situation until you or the community can come up with an idea on how to manage the more realistic part.
Answer by Oribow · May 22, 2016 at 09:40 PM
You can make it work with only two layers, if interior things dont have windows. Have one layer for interior things and another for space things. Then just switch the camera render layer and the collision layer of the player between the two. There is no reason for giving each interior its own layer, when the player cant see on from the other. Second way: Have a new Scene for each interior level and just load it on teleport. Thats probably the cleanest version.
I don't think a multiple scene approach would work, because multiple players/entities will be in different ships simultaneously. To my knowledge, Unity can only load one scene at a time.
Similarly, I don't think I can achieve this with only two layers, at least from a collision standpoint. Entities in different ships would collide with each other if they existed in the same space and the same layer.
Each interior space has it's own set of coordinates, centered on x,y = 0,0. The reason for this is this is to avoid moving levels colliding with moving units, which often causes unreliable collision detection and physics errors. Ship interiors are concave meshes, which also prevents them moving.