Problem adding node to CharacterControl

I’m attempting to modify the HelloCollision tutorial ( by adding a node associated with the CharacterControl. The relevant code looks like this:

// We set up collision detection for the player by creating
// a capsule collision shape and a CharacterControl.
// The CharacterControl offers extra settings for
// size, stepheight, jumping, falling, and gravity.
// We also put the player in its starting position.
Node playerNode = new Node(“playerNode”);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setPhysicsLocation(new Vector3f(0, 10, 0));

// We attach the scene and the player to the rootNode and the physics space,
// to make them appear in the game world.
shootables = new Node("Shootables");

The behavior I’m getting is that the player is not initially making contact with the ground, and when the game starts, the player appears in the correct initial position, then immediately begins falling through the floor of the scene. I’ve tried modifying the initial location with setPhysicsLocation, but that didn’t seem to help. What am I doing wrong here?

Is your landscape a physical object ? Is it in a group that can collide with your character ?

Yes, as mentioned in the original post, I’m modifying the Hello Collision tutorial. Before adding these three lines, the tutorial code works fine and the CharacterControl behaves properly, colliding with the physical landscape and supporting the player.

Node playerNode = new Node(“playerNode”);




If these lines are added to that tutorial, upon starting the game, the behavior is as I described…the player falls through the landscape. I really don’t understand how that would be the case, but it is…that’s why I was hoping someone here could tell me what’s going on.

So… To summarize…

  1. the tutorial works well but the character is not visible.
  2. you attach the characterControl to a node, and then there is no more collision with the floor.

That’s it ?

I’ve never worked with this yet. But I find it strange that you attach it to an empty node. Have you tried attaching the control to some kind of ‘real’ object ?
The node is a mere container. With nothing in, it has no size. My hypothesis (gratuitous) is that the character adapts to this null size… But maybe I’m totally wrong.

Yes, that’s exactly what happens.

And yes, I’ve tried adding a geometry to the node before adding the control…same behavior. I’ve also tried instantiating the node using the model from the Walking Character example:

[java]Node playerNode = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);[/java]

Same deal. In both cases I can see the geometry/model, so it’s loading fine. But the control is not colliding with the floor and the player falls.

Your SetPhysicsLocation will be cleared when you attach the player to the playerNode, as it will go to the location of that instead.

Do this:

player.setPhysicsLocation(new Vector3f(0, 10, 0));

or this ( assumming playerNode is at world origin)):
playerNode.move(0, 10, 0);

1 Like

Aha…okay, thanks. Works now. :slight_smile: