Attaching BetterCharacterControl to a Node

Hia monkeys. I have a planet that orbits a star, and it rotates on its axis as it does so. The orbit is done with a node in the center of the star that just rotates. I’m trying to find a way to attach the player using BetterCharacterControl to the planet so that the player stays with the planet as it rotates and revolves. I have tried setting the location of the player to where they should be on the planet in simpleUpdate, and it works, except it stops all gravity and movement. I have tried attaching the player to a node and then attaching that node to the planet’s node, but it does nothing. I have also tried attaching the player’s spatial to the planet’s node, still nothing. How would I do this? I’ve done just about everything I can think of. Thanks!

It seems nobody knows… I had another idea, but it requires some sort of “update” method to tell me when the player’s location has been updated due to gravity. Is there anything like that?

I’ve not really used the physics stuff - so haven’t replied earlier… but 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.

That might do it! Thanks, I’ll test it out and see how it goes. :slight_smile:

This is what the “applyPhysicsLocal” flag on physics objects is for, check its javadoc.

I couldn’t figure out how to “move” the PhysicsSpace, but maybe I’ll find an answer later. As for normen’s idea,

<cite>@normen said:</cite> This is what the "applyPhysicsLocal" flag on physics objects is for, check its javadoc.

Maybe I’m doing something wrong here, but here is what I am doing:

float x = planet.getPlanetNode().getWorldTranslation().subtract(player.getLocation()).x;
float y = planet.getPlanetNode().getWorldTranslation().subtract(player.getLocation()).y;
float z = planet.getPlanetNode().getWorldTranslation().subtract(player.getLocation()).z;

this.player.setGravity(new Vector3f(x, y-10f, z));

This happens in simpleUpdate, so the player is constantly readjusting as the planet moves. The player has applyPhysicsLocal as false. Basically the player is only moving to the correct spot when they are in the air, otherwise they stay still and eventually fall off the planet. Also if the planet orbits too fast, the player can’t keep up. I’m sure the answer is right in front of me, but I can’t see it. Thanks! :slight_smile:

I was able to fix this by overriding update(float tpf), calling super.update, and then moving the player to where they should be based on their current location and the planet’s location, also adding in the movement from using the wsad keys. It’s not very efficient but efficiency isn’t on my priority list right now. Thanks guys!

If you just set its location why use a character at all?

<cite>@normen said:</cite> If you just set its location why use a character at all?

The character applies all the gravity and physics for me, like bouncing off the ground, etc. I only move the player a tiny bit after the physics have been applied, so I’m not actually applying physics. All I really do on top of moving the player is add the walkdirection so they can move when the wsad keys are pressed.

If you set a physics objects location directly without kinematic mode you “beam” it and can not expect any physics computation to be right.