I have a planet where ships can fly around and I need to add all the ships elements to both physics spaces.
-the planet physics space
-the ship physics space (where all rigidBodies are in local mode so that I can move around in the ship when it’s flying)
When I add the ramp to the second physics space it crashes. I need the rigidbodys of the ships ramps to be copied into the planet physics space without influencing the spatial. Basicly a dummy that follows the world position of the actual ramp.
You can’t because it stores specific information about the physics state of the object. But you can use the same collision shape, thats also the only thing taking up any relevant amount of memory. Depending on how complicated your setup will be you might have to get off using the Controls and use PhysicsRigidBody yourself (possibly creating your own control to apply the physics data to the spatial).
At which moment do you plan to migrate the character’s body from a space to the other?
On landing :
clone the ship’s collision shape and attach it to the planet
detach the character collision shape from the ship
attach it to the planet
On take-off :
detach the character collision shape from the planet
attach it to the ship
destroy the ship’s physic clone
With this approach, you manage the hull of your ship as well, not only the ramp.
You can also choose to migrate all the collision shapes contained in the ship physic space to the planet. It allow to change, for exemple, the gravity to applyinside the ship, to manage an object that fall down the ship, and insure that your character continue to interact with all that is inside the ship.
Well … do you know what a scenegraph is? (Else read “scenegraph for dummies” first!)
It’s simple: You have the planet’s physics space relative to (0,0,0) (world center).
You have the space ship at (ship.x,ship.y,ship.z) (ship space)
You have a Node for the ramp (ramp.x,ramp.y,ramp.z) (ship space)
You now need to get the worldspace of this node (there is a convenient jME function for that simple thing).
The world space in relation to the ship space is the INVERSE matrix of the ship space.
So by applying the inverse matrix to the ramp spatial, you get it in relation to the planet.
You then take the ramp out of the ship physics space and add it to the planet physic space.
You will of course use the kinematic-type of physics (not dynamic) that’s clear, isn’t it?
Only one problem remains: If your astrounaut jumps onto the ramp, he must stay attached to the ramp and move with it. You would simply “glue” him to the ramp when he is on the ramp and give him the velocity vector of the ship once he jumps into the air. When he touches the ramp again, you “glue” him back to the ramp. If an object (e.g. a tree) strikes the astronaut on the ramp, then you “unglue” him again and set his velocity to zero (so he most likely will fall out of the ship).
Sorry, but I can’t explain that any simpler without forking too much time to help others…
Make two physics control objects for your astronaut. (and two spatials - one is invisible)
Make two physics control objects for the ramp. (and two spatials - one is invisible)
Only one physics control will be “dominant” - e.g. be the master to the inactive other one.
When the astronaut is on the ramp, the dominant one is that physics control which is in ship space.
When the astronaut jumps from the ramp, then the dominant one is the control which is in planet space.
So you basically have two spatials which represent the same entity (the astronaut).
One of the two astronauts is invisible when the other one is visible.
The dominant astronaut and the dominant ramp control the behavior of the physics.
The not-dominant astronaut and not-dominant ramp are moved via kinematic physics movement.
The only real problem is to decide when to switch from one to the other.
In other words: “When does dominant become not-dominant? When does not-dominant become dominant?”
You will have to write a ray test or other collision test to find out when the astronaut is on the ramp.
So you need to find out when to “glue” the astronaut to the ramp and when to “let him fly”.
But that seems to be an easy problem that I could solve in a few minutes with standard physics…
Yup, your last post is the solution I am going with.
Since the ship is build-able part by part, I also have to think about what happens if someone builds a ship with a corridor that is open to space and other parts like airlocks or a section of hull being destroyed in combat (ok, that last one will be for another post )
Maybe I can check “Is on ground” to tell when the player is no longer touching the ship. If the player is lower then the floor I switch physics space and if he is above it means he jumped. Too high and it switches also.
-If players speed vector matches close to ship speed vector and withing a certain radius of that ship, player stays “gravity locked” to the ship (will make EVA a bit more enjoyable, with mag boots to stick to the hull when outside the ship)
Same but no gravity lock when close to ship. If the player is beneath the deck, switch to planet physics space. If the ship is flying upside down and the player exits the ship, I guess I need a ray test to see if anything is directly above or below the player.
Ramp is a bit special, I think I will only allow ramp to go down when ship is landed. Unless I use ray casting to detect when on ramp.
So I get a clone of each part and cull it from the view? Guessing this should not lower performance too much… I can mix batching and instancing right, but things that are culled will not impact performance?