Positioning character model in capsule collision shape

Hello again Monkeys, have another question for you since the latest physics updates.



When testing the capsule collision shape (based on the testWalkingChar method) with a test model I get this:







Editing the local translation on the -y axis seems to have no effect.



Code used is:



[java]

/**

  • Player

    */

    private void createCharacter() {

    CapsuleCollisionShape capsule = new CapsuleCollisionShape(0.55f, 1.1f);

    player = new CharacterControl(capsule, 0.01f);

    playerModel = (Node) assetManager.loadModel("Models/TestChar.mesh.j3o");

    playerModel.setLocalScale(0.5f);

    playerModel.setLocalTranslation(new Vector3f(0f,-1.0f, 0f));

    playerModel.addControl(player);



    player.setPhysicsLocation(new Vector3f(-10, 30, -10));



    player.attachDebugShape(assetManager);

    //player.setJumpSpeed(1200f);

    player.setGravity(25.0f);

    player.setFallSpeed(600f);

    player.setMaxSlope(0.55f);



    rootNode.attachChild(playerModel);

    getPhysicsSpace().add(player);



    }

    [/java]

Your player models center is at its feet, either move it down in the modeler, move the geometries down or attach it to a Node, move it down and add the player control to that Node.

normen said:
Your player models center is at its feet, either move it down in the modeler, move the geometries down or attach it to a Node, move it down and add the player control to that Node.


well thats good to know, I always center my characters and rigs at the feet.......... it feels more natural to me to center a character where it is most likely to contact the the ground...... some how ;), in jme2 I also had to adjust the character positions the match the collision shape...........is any reason why manipulating center position are not supported in code

Hello!



hah, I still use the feet! I just attach the physics shape with an offset of the height! I’mma cheater! :stuck_out_tongue:



Cheers!

~FlaH

mcbeth said:
is any reason why manipulating center position are not supported in code

I could possibly add an offset variable or something to the Character Control, I am also thinking about auto-rotation of the character in the walkDirection, however none of that is in bullet directly and atm I pretty much just use whats available in bullet.
normen said:
I could possibly add an offset variable or something to the Character Control, I am also thinking about auto-rotation of the character in the walkDirection, however none of that is in bullet directly and atm I pretty much just use whats available in bullet.


Sounds like a nice feature :)

Adjusting the characters pivot point did solve this, tried it with a work in progress model, I'll just have to adjust my wip rig when i get the time :) Also this is a test render with current pssm, and one ambient light.

This is also a few other things I have noticed with the controls of the physics character.



When moving forward + sideways, the player seems to double its speed.



And was curious if there is an example of changing the left / right from moving side to side to rotating the player?



Thanks.

TestWalkingChar does these things with the character. The fact that he walks faster is simple vector math, it was like that in Doom too :wink: Just normalize the vector after adding the forward and sidewards vectors.

One other thing I have noticed with the chaseCam is this. When rotating the view above the physics character the player object seems to be affected by a force seeming to push from the cam. As in the camera seems to be adding resistance to the player against the ground. (i.e it slows down from a resistance force pushing down on the -y).



And thanks for pointing me back to test walking char for the rotation, seems I still have a bit to learn in the ways of handing rotations :slight_smile:

lwsquad said:
One other thing I have noticed with the chaseCam is this. When rotating the view above the physics character the player object seems to be affected by a force seeming to push from the cam. As in the camera seems to be adding resistance to the player against the ground. (i.e it slows down from a resistance force pushing down on the -y).


Walk direction is set by camera direction. If you look straight at the ground your character attempts to move into the ground. If the move speed is higher than gravity you can look up and fly! The fix I found was to only use the horizontal rotation of the camera using the camera look direction -> quaternion and setting the rotation with that. Here's the code if you need it but you probably know how to do it already.

[java]if (move[0])
{
Quaternion quat = new Quaternion();
quat.lookAt(camDir, new Vector3f(0, 1, 0));

float[] temp = new float[3];
temp = quat.toAngles(temp);

Quaternion rotate = new Quaternion();
rotate.fromAngleAxis(temp[1], new Vector3f(0, 1, 0));

character.setLocalRotation(rotate);

moveDir.set(new Vector3f(FastMath.sin(temp[1]), 0, FastMath.cos(temp[1])).mult(speed));

Vector3f offset = new Vector3f(cam.getDirection().mult(-10f));//this is so the camera goes behind the character
cam.setLocation(player.getLocalTranslation().add(offset));[/java]

Or what you can do is get the cam direction, set the Y value to 0, and normalize the vector.

You’ll always have an horizontal direction.

I am also having issue positionning my character model in a capsule collision shape.
Where do we stand on adding an offset variable to the CharacterControl, as mentioned above by Normen ? Could someone point me in the right direction to do this ?

Add the model to a node, add the physics control to the node. Move the model until it is right.

1 Like

Thank you very much !
I was adding the control to the model instead of adding it to a new node.

I am having this exact problem, but I am confused by one thing. In the original post the screenshot displays the collision capsule. I have been trying to do this, but it doesn’t seem to work.

I see in the poster’s code (And elsewhere online) the use of player.attachDebugShape(assetManager) I have tried to use this in my own code, but the parameters don’t seem to match. For PlayerController.attachDebugShape() it’s expecting the parameter to be a Material.

Am I missing something?

Thanks