Starting Space Sim - Need Direction

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
meathelix
Posts: 14
Joined: Tue Oct 19, 2010 6:39 pm

Starting Space Sim - Need Direction

Post by meathelix »

I'm currently working on a bit of a nonstandard space sim, in that the player can exit control of the craft and walk around the ship at any time, as well as walk from one ship to another docked ship, walk from a ship to a space station interior, etc.

What I have are basically a few different collision and physics frames of reference that overlap each other here and there, and I need to know if Bepu has the features I need for such an endeavor in addition to some general advice on which direction to start exploring and implementing. I'm a long time programmer and game dev, but this is my first serious foray into integrating a physics engine into a 3d game.

Quick basics:
  • The ships are an assemblage of 3d tiles that are basically defined in a 2d array. Everything is on a grid and everything is fairly low-fi in the visuals, e.g. lots of box shapes.
    The player can walk around the ship, through corridors and rooms all made from these tiles.
    The player can pilot the ship.
    When a ship fires on another ship, that shot can register as damaging a specific tile
    Ships can dock with one another.
    There may or may not be gravity inside of a ship.
    The player may be able to walk on the exterior of a ship, given the continuous nature of the sim I'm going for.
My initial thoughts are separating the collision into different groups with ship to ship stuff, player inside ship stuff, player on exterior stuff, etc. Ships would just be spheres to one another until a shot penetrates the collision sphere, then I can check which tile (box) was hit.

For a player inside a ship, I could do AABBs for the walls and other macro shapes, with the axis in question mapped to the orientation of the ship. The collision with these would only be relevant to things inside the ship, so alignment should save me some cycles there.

Eventually there will be more complicated things like destructible ships and planets, but I'm trying to tackle a smaller, more manageable chunk first before working up to something a little less sane.

Does this sound doable? Where would someone recommend that I start poking around?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Starting Space Sim - Need Direction

Post by Norbo »

Here's some things you might encounter while doing something like this:

-Need for a custom character controller. The sample ones are pretty simply designed and made for a world with predictable gravity. Depending on your needs, making a custom one might not be too bad, but character controllers can be very, very annoying to get tuned well. BEPUphysics can provide its sweep tests and raycasts to assist, but that's rarely the hardest part. The more restrictions you can put on your world, the easier it will most likely be (which applies to a lot of things).
-Custom collision shape and collision test. Technically, this is doable in v0.14.2 and before, but it's not a very well defined process involving custom entity types and significant work to make sure everything is hooked up right. Usually the recommendation is to use a CompoundBody, which has its own acceleration structure. However, depending on the type/size of ships and your target platforms, a more specialized solution may be required. The upcoming v0.15.0 makes the narrow phase systems more extensible which would help out a lot.
-Depending on the scale of the simulation, you may need to cull a lot of things. If the game has a 'massive' universe you can fly around in, you would have to look into something like this: http://www.bepu-games.com/forums/viewto ... ?f=4&t=971. If for some reason you find the need to handle 'interior' and 'exterior' Spaces separately (which may come in handy in some cases), you also have to handle the transition where they switch from Space to Space.

Piloting ships, damaging ships, and applying appropriate gravity forces are all sort of secondary relatively simple problems. Dynamic objects can be pushed around with forces to simulate gravity for people inside or a ship's engines.

The BroadPhase can handle the high level pruning, so you probably won't need to worry about representing them with spheres. They'll already be considered an AABB in the broadphase. Narrow phase collision checks will not occur until the AABB overlaps with another object's AABB.
Does this sound doable? Where would someone recommend that I start poking around?
So basically, yes, it is doable. There will be a good bit of custom work required depending on your specific simulation needs. It will be easier after v0.15.0, but this sort of simulation still has a lot of special requirements.

For starters, I'd just mess around with some simple simulations to get a feel for the overall layout of the engine. The organization is going to change in v0.15.0 pretty dramatically, but the core ideas and processes of the engine are not. Once you are comfortable with how things hook together, you might try building a simulation towards the end goal piece by piece and hopefully v0.15.0 will be out by then too.
meathelix
Posts: 14
Joined: Tue Oct 19, 2010 6:39 pm

Re: Starting Space Sim - Need Direction

Post by meathelix »

I've played a bit with the engine now and am wrapping my head around some of the concepts.

Would it be crazy to have a separate space for each interior? There will probably only be one active interior at a time since it's a single player game, or perhaps a few since the player could enter and exit while docked at a station, and I would want to have AI in those areas persist between visits.

Anyway, my initial thought is to give an interior its own space so I can take advantage of "global" gravity. Sim everything inside and then transform all of that by the ship's root world matrix. Give the ships their own space that represents the exterior so they can bump into each other, fire shots, etc.

There are unfortunately a couple of ideas I had that get nullified by this approach, but it might be for the best anyway since they were more ambitious and could stand to wait for a sequel or subsequent development 'layer' to be added on.
  • First is the concept of localized gravity. Having a space per ship with gravity set to "on" means I can't have sectors within a ship that have gravity disabled. I also can't do some 2001 stuff with hallways that extend vertically from a space but have their own "down" vector so you can walk along them.
    Second is the idea of ships breaking apart. I like the idea of a ship taking enough damage to breach the hull and potentially knock chunks off that the player could be standing inside. With mag boots and an environment suit, the player could survive inside the chunk and hop between them to try and survive.
The player is currently a dynamic cylinder with its velocity set directly by the player's input. I'm going to have to pour more work into it to support jump and crouch, plus 0-G maneuverability.
Do I sound like I'm on the right track?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Starting Space Sim - Need Direction

Post by Norbo »

Would it be crazy to have a separate space for each interior?
Not at all. However, the global gravity is a relatively small part of the reason why this helps (though it is certainly convenient).

If you go for the space-per-interior approach, I'd recommend embracing it completely. The 'interior' frame of reference would view the ship it manages to be close to the origin and stationary. This simplifies a lot of relationships and interactions while aboard the ship. All velocities would be relative to the ship you're on, as opposed to some 'absolute frame' of the exterior space.

Due to interiors being separate spaces, you'd need to control the interaction between the 'inside' and 'outside' carefully. It wouldn't be easy to shoot a gun through a window at a person inside the ship, for example. If you have airlocks, it would give you a very simple and controlled method to switch from the 'exterior' space to the 'interior' space.

In effect, the exterior of a ship is the only thing that truly inhabits the exterior space. When the player moves from the exterior to interior, the exterior no longer exerts any control on that player.
First is the concept of localized gravity. Having a space per ship with gravity set to "on" means I can't have sectors within a ship that have gravity disabled. I also can't do some 2001 stuff with hallways that extend vertically from a space but have their own "down" vector so you can walk along them.
Gravity is just a little change in velocity each frame and is a very small component of the simulation, so you could manage it in different ways if you wanted. In ships that require custom gravity, you could keep the ship's internal gravity off and manage it directly based on areas of the ship.
Second is the idea of ships breaking apart. I like the idea of a ship taking enough damage to breach the hull and potentially knock chunks off that the player could be standing inside. With mag boots and an environment suit, the player could survive inside the chunk and hop between them to try and survive.
That is indeed more difficult with the interior space model. Once you no longer have a simple space to space switch like airlocks, the interactions between the two spaces suddenly become far less restricted and a lot more difficult to manage. There's not really a great solution apart from handling specific cases as best you could. Perhaps after significant damage, the interior space's simulation objects would be transformed up into and added to the exterior space, allowing them to behave appropriately.
The player is currently a dynamic cylinder with its velocity set directly by the player's input. I'm going to have to pour more work into it to support jump and crouch, plus 0-G maneuverability.
Do I sound like I'm on the right track?
Pretty much, yes. I do have one suggestion about the character controller though- if you can avoid having 'stepping' behavior, it makes things substantially easier :)
Post Reply