ValkyrienSkies / Valkyrien-Skies

Moving structures powered by a custom multi-threaded physics engine; in Minecraft.
https://valkyrienskies.org/
Apache License 2.0
161 stars 40 forks source link

Feature Request: Change gravity orientation on ships #389

Open traverseda opened 4 years ago

traverseda commented 4 years ago

I'm just looking at the change over to bullet physics and it occurred to me that you're probably in the midst of overhauling the physics engine right now.

One feature I think would be nice for spaceship style games is setting the gravity independent of the world gravity. What I mean is that mods spaceships should be able to fly upside-down and players should still fall towards the "bottom" of the ship. This would allow for actual 3D ship piloting, including pitch yaw and roll.

That's probably outside of the scope of the mod right now, as you'd also need to overhaul player controls and camera-orientations, but those hacks can be added in by some other mod down the road, a mod like "up and down", as long as they have a basic API for setting gravity orientation on ships.

Rubydesic commented 4 years ago

The tricky thing with this is determining what is 'inside' the ship. What if the player falls upside down and out of the ship, for example. Do they keep going up? How do we know when they've exited the ship?

traverseda commented 4 years ago

I suppose the obvious thing would be to make that mod-configurable, although I think a simple hull operation would work well in 90% of cases. I know bullet has a reasonable convex hull physics option, and if you're already integrating bullet with the minecraft physics engine you could provide some simple methods to check if an entity is within that convex hull, or within a few other simple bullet shapes? I'm not terribly familiar with minecraft's internals, so I don't know if that makes sense, but I can imagine that would be a generally useful tool for mod authors.

A simple "is this entity within the convex hull of this ship" API call coupled with the ability to set gravity direction/strength/other-forces on entities should work. It also has the potential to let mod authors do things like apply buffs to anyone who's on a given ship.

If you wanted to get really fancy the ability to not include specific block types in the convex hull check could be nice maybe? Useful for things like force-fields or tractor-beams, or rope ladders or whatever.

traverseda commented 4 years ago

The only real case I can thing where the convex hull wouldn't work is if you're standing on the very top surface of a completely flat object. I think a convex hull is more than good enough, but if you wanted to adjust that making it convex hull plus two ~meters~ blocks would work.

The other way to do is would be to work with fully or nearly-fully enclosed spaces, but that would require a much more complicated algorithm. It would be good for situation where you wanted a "pressurized" vessel of some kind, and you wanted to be able to detect air leaks. Seems like more effort than it would be worth and it wouldn't be nearly as generally applicable. That could be some sort of voxel flood-fill algorithm, but I'd leave that to other mods.

deltanedas commented 4 years ago

simple

  1. add gravity block to ship
  2. set radius like with lift lever or in a gui
  3. dont fall off ship wow
  4. maybe press a key to visualize its area, or when looking at the gravity block
traverseda commented 4 years ago

Yeah, giving modders the tools to make that kind of thing would be great. Gravity generators or gravity plating could be a lot better than the convex-hull solution for some types of mods. In my mind it's more about giving modders the tools to make those kind of solutions.

deltanedas commented 4 years ago

if gravity plating works how i think you want, it could work like that gravity carpety block in starminer

Rubydesic commented 4 years ago

Yea, we could certainly let mods check if a player is within the convex hull of the ship, although tbh I'm not sure how useful that is with issues arising as you said with weirder shapes like a flat surface etc.

I know that 'gravity' mods exist already which just edit player velocity within a certain radius. This should probably already work with valkyrien skies with minimal compatibility code (or none at all). Coupled with some calls to the API to figure out the orientation of the ship, a basic 'gravity block' using a radius check would be really easy to implement even with the mod as it stands.

traverseda commented 4 years ago

Good to know, It's really impressive that mods that would check things like player radius would work without needing any extra compatibility coded in.

with issues arising as you said with weirder shapes like a flat surface etc.

I think most of the time a convex hull will match player expectations. I'm imagining situations with masts, situations with multiple weird spires, docking bays, etc. For the most part all the shapes I can think of match my intuition of what would be considered "inside" of a ship, except for standing on the deck of a perfectly flat ship. As soon as you add in a mast or a balcony the problem is solved though, and everything matches my intuitions again.

Although I should clarify that it's less if the player is within the convex hull and more that the player is touching or intersecting the convex hull.

Rubydesic commented 4 years ago

Well, I think something like that is more up to the mods, although we can expose an API for generating the convex hull of a ship. You should make another feature request issue for that and reference this one.

kaliisteele commented 4 years ago

up and down and all around already has methods of changing a players gravitational orientation, so it would likely just be a matter of making a compat layer between them