BetterCharacterControl Location

How do I get the BetterCharacterControl’s location previously with CharactorControl I could just call a getPhysichsLocation(); but this new class dosen’t have one. At the moment I am getting the location from the node that has the control. Is there a proper method of getting physics location from a BetterCharacterControl?

That is the proper method.

1 Like

Thanks

@normen said: That is the proper method.

Is it really?
I tried to use it like this but after I changed the parent node of spatial I controlled with BetterCharacterControl the returned physical location and the returned spatial location where out of sync. Moreover the location stored by the BetterCharacterControl was the correct one.

Or should I do something after I switch the parent node, to make the locations in sync again?

@yezu said: Is it really? I tried to use it like this but after I changed the parent node of spatial I controlled with BetterCharacterControl the returned physical location and the returned spatial location where out of sync. Moreover the location stored by the BetterCharacterControl was the correct one.

Or should I do something after I switch the parent node, to make the locations in sync again?

The physics-geometry relation is always one frame late. I don’t know what you do but you seem to do it wrong somehow.

Hello everyone. I’m new to JME and 3D engines in general, so bear with me.

I’m working through the tutorials - specifically Terrain Collision. I’ve tried updating the code to use BetterCharacterControl, but I’m getting strange effects relating to the camera position.

Note that the terrain is just a flat square and I update the camera’s position with cam.setLocation(playerNode.getLocalTranslation()).

Now, this code works as expected - the player stands and walks on top of the terrain with the camera positioned at the top of the capsule:

[java]

playerNode = new Node(“Player node”);
playerNode.setLocalTranslation(new Vector3f(-10, 10, 10));
rootNode.attachChild(playerNode);

CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, .05f)

playerNode.addControl(player);
bulletAppState.getPhysicsSpace().add(player);

[/java]

Changing this to use BetterCharacterControl, I do this:

[java]
playerNode = new Node(“Player node”);
playerNode.setLocalTranslation(new Vector3f(-10, 10, 10));
rootNode.attachChild(playerNode);

player = new BetterCharacterControl(1.5f, 6f, 1f);

playerNode.addControl(player);
bulletAppState.getPhysicsSpace().add(player);
[/java]

But this results in the camera dropping inside the floor.

What should I be doing to make the BetterCharacterControl player behave the same as CharacterControl (with respect to the camera’s position)?

@normen said: The physics-geometry relation is always one frame late. I don't know what you do but you seem to do it wrong somehow.

Only now I managed to check what was going on. Apparently I made multiple checks of the location of the Node in one frame. One of which would reassign it to another parent. Once I postponed the moving after all checking was done, it started working correctly,

So thanks a lot :slight_smile:

@davekidd said: (...) But this results in the camera dropping inside the floor. (...) What should I be doing to make the BetterCharacterControl player behave the same as CharacterControl (with respect to the camera's position)?

For BetterCharacterControl the origin is at the bottom of the capsule (as it should be if you ask me :P) So when simply asking for translation you will get the location of the bottom of the capsule. In effect you simply need to translate the cam up.