Moving a PhysicsSpace

Hi! My goal is to create a planet that revolves around a star, and allow players to wander around on the planet, drive cars, etc, while it moves. I already have this working successfully by attaching the planet to a node in the center of the star, then rotating the planet node and star node independently to create both the motion of the planet rotating on its axis as well as the planet revolving around the star, and I use quaternions to rotate the player, and they do stay on the planet while it rotates and such. The problem is that it is very unstable with physics involved. Players can easily walk through objects, when they are falling it is jittery, etc. A while ago I created a topic about keeping the player on the planet and “zarch” said “…I think the solution would be to set up a physics space for the planet and have it effectively stationary.” Here’s the post. I am still using BetterCharacterControl.

Basically what I want to do is just what zarch said, create a PhysicsSpace and attach it to the planet while it rotates, that way I won’t need to update the players’ positions and such, only the PhysicsSpace. The problem is moving the PhysicsSpace. I don’t know how to do this, or if it is even possible. Does anyone know?

Thanks :slight_smile:

Sorry, I didn’t quote everything I wanted to from zarch. Here’s a better quote:

"I think the solution would be to set up a physics space for the planet and have it effectively stationary.

i.e. run all the physics state stationary and then move the entire node and entire physics space to produce the movements of the planet.

Once you leave the planet switch off physics again (or change to “space physics” mode) until you get close enough to another one."

Off Topic Edit: Why can’t I edit my main post, but I can edit my replies? That’s odd.

Its actually pretty easy, you just make multiple physics app states and set the physics control to setApplyPhysicsLocal, then you attach the respective spatials all to one node and treat it as the local physics system, i.e. the planet.

1 Like

Thank you normen! I’ll try this out and let you know how it works.

I’m probably misunderstanding what I’m supposed to do. Here’s what I’m doing:

First I create a node for the player and attach the control to it:

[java]
playerNode = new Node();
playerNode.addControl(this);[/java]

Then I assign a planet to the player:

[java]
public void setBulletAppState(BulletAppState state)
{
if(this.bulletAppState != null)
{
this.bulletAppState.getPhysicsSpace().remove(this);
}
this.bulletAppState = state;
this.bulletAppState.getPhysicsSpace().add(this);
}

this.setBulletAppState(planet.getBulletAppState());
planet.getPlanetNode().attachChild(this.getNode());
this.setApplyPhysicsLocal(true);[/java]

This should add the player’s node to the planet’s node, as well as add the player to the bulletAppState assigned to the planet. When the planet rotates, though, the player doesn’t move with it. I know I left out a lot of code, if I need to post more let me know, feel free to ask me all kinds of questions, I really don’t know where to go with this :stuck_out_tongue:

Thanks for the help. :slight_smile:

You should do something like:

[java]objectGeom1.addControl(physicsControl1);
physicsSpace1.add(physicsControl1);
planetNode.attach(objectGeom1);

//other planet and object
objectGeom2.addControl(physicsControl2);
physicsSpace2.add(physicsControl);
planetNode2.attach(objectGeom2);[/java]