Capsule collision psychics between characters

I haven’t worked with networking but from what I’ve been reading, I believe you’d actually want to send the walkDirection vector from the server rather than the world location. The Better Character Control does store a world location, but it is protected in the BetterCharacterControl class and can only be altered by using .setWalkDir();, otherwise you use the charControl.warp() method to move the control.

So for the AI and NPCs in your game, you would send any pathing or movement results to their respective character control on each client.

And for the players you’d want to send the input event from each client to the server when they make a movement action such as pressing “w” “a” “s” “d”, and then you interpret this input on the server, and send back the corresponding walk direction. You shouldn’t send the player’s coordinates to the server because, if im correct, sending a variable like a Vector would allow players to hack your game much more than if you send, for example, strings that each simply represent an input event.

2 Likes

How to setup start position, current code:

    characterControl = new BetterCharacterControl(1.1f, 3.1f, 1);
    
    //      characterControl.getPhysicsSpace().addCollisionListener((PhysicsCollisionListener) characterControl);

    
    //characterControl.setCollideWithGroups(group_1);
    //characterControl.setCollisionGroup(group_1);

    characterControl.setJumpForce(new Vector3f(0,5f,0));
    characterControl.setGravity(new Vector3f(0,1f,0));
    characterControl.warp(new Vector3f(0,10,10)); // warp character into landscape at particular location
   
    
    
    
    characterModel = (Spatial) assetManager.loadModel(modelPath);

    characterNode = (Node)characterModel;

    //characterModel.move(0.050779365f, -1.74886445f, 12.0f);

    characterModel.rotate(1.0f, 0.0f, 0.0f);


    characterModel.setLocalTranslation(new Vector3f(0, -0.2f, 0));
    
    
    characterControl.setWalkDirection(startLocation);

add in game

            int node_id = game.rootNode.attachChild(player.characterNode);

            game.bulletAppState.getPhysicsSpace().add(player.characterControl);
            
            game.bulletAppState.getPhysicsSpace().addAll(player.characterNode);

Player init under level how.

1 Like

I agree 100% - good developers don’t ditch the documentation. Good developers carefully read the documentation and keep it handy for reference because the more you use documentation the better the quality of your code is likely to be and you’re less likely to waste precious time chasing your tail in circles because you didn’t read the documentation. I’ve been developing in Java for about 8 years now, and I still spend a good deal of time reading through the JDK javadocs - because the possible ways I could think to solve a problem off of the top of my head may very well not be the best ways to solve the problem. In general, I find that the more attention I pay to documentation the better my code is and the easier my life is (much less time spent chasing down bugs that could have been avoided by reading documentation first).

It’s good that you have a good background in programming, but just because you can program doesn’t mean you can dive into a brand new framework (and field - as I recall in another thread you mentioned being new to 3D programming) and expect to get good results without taking your time to first learn the new framework (or field). jME is not a small or simple engine. It’s an extremely powerful and well designed engine, but it’s going to take time to learn. Taking a few hours now to read the documentation and carefully design your code could save you weeks of frustration later, especially as you are talking about multiplayer games and servers. Oftentimes trivially simple things in single player games become 100x harder to do right in a multiplayer game. As far as your current problem goes, a few hours reading the documentation could save you many hours of duplicating built-in engine functionality (collisions) in order to get something that’s far less capable than what’s already in the engine.

You’re moving your character -0.2 world units straight down when you add him. If he’s appearing under the floor when you start the game I’d suggest you move him up until he’s above the floor.

3 Likes

Yes. new language or engine or framework = newbie.

update code:

    characterModel = (Spatial) assetManager.loadModel(modelPath);

    characterNode = (Node)characterModel;
    
    characterControl = new BetterCharacterControl(1.1f, 3.1f, 1);
    characterNode.addControl(characterControl);


    characterControl.setJumpForce(new Vector3f(0,5f,0));
    characterControl.setGravity(new Vector3f(0,1f,0));
    characterControl.warp(new Vector3f(0,10,10)); // warp character into landscape at particular location
   
    characterControl.setApplyPhysicsLocal(true);
1 Like

Stand under level.

When i use character control i can set physical position…

1 Like

Use BetterCharacterControl. Please use warp() to set the position of the player

1 Like

Use thanks.

Now character stand at place.
But camera at flor level.
And i have slow speed:

How to set speed and camera level?

1 Like

You set the speed with setWalkDirection(yourWalkDir.multLocal(4f));
The cam place is your thing, dude!
From now on, I am not going to help you anymore, because everything you ask is explained in the WIKI
WIKI
WIKI
WIKI
WIKI

People invested god knows how many hours to write this, so please show respect and read this!!!

3 Likes
    characterControl = new BetterCharacterControl(1.5f, 6f, 1f);
    characterNode.addControl(characterControl);


    characterControl.setJumpForce(new Vector3f(0,5f,0));
    characterControl.setGravity(new Vector3f(0,1f,0));
    characterControl.warp(new Vector3f(41.63642f,12.0589485f,-36.97022f)); // warp character into landscape at particular location
   //        "1"     : { "x" : "-41.63642f",  "y" : "12.0589485f", "z" : "-36.97022f"},

    characterControl.setApplyPhysicsLocal(true);
    
    
    under level

okay try second

1 Like
update method:

    /**
     * Move and rotate model
     */
    walkDirection.set(0, 0, 0);
    
    if (Left) {
        walkDirection.addLocal(camLeft.mult(speed));
    }
    if (Right) {
        walkDirection.addLocal(camLeft.mult(speed).negate());
    }
    if (Up) {
        walkDirection.addLocal(camDir.mult(speed));
        //rotate_channel.setLoopMode(LoopMode.DontLoop);
    }
    if (Down) {
        walkDirection.addLocal(camDir.mult(speed).negate());
    }

    characterControl.setWalkDirection(walkDirection.multLocal(8f));

    

    float[] angles = new float[3];
    camRotation.toAngles(angles); // we get the cam angles here
    angles[0] = 0; // you don't want to rotate along the x-axis, so we set it to 0
    angles[2] = 0; // you don't want to rotate along the z-axis, so we set it to 0
   
    characterModel.setLocalRotation(characterModel.getLocalRotation().fromAngles(angles));

slow

camera have low position…

you want say what not need set position (hands program method)?

1 Like

not work.

when i press “S” character fly to the sky…

1 Like

now i have you old problems character bouncing and not rotate…

1 Like

Error - not add control to model…

   characterModel = (Node) assetManager.loadModel(modelPath);

        
        
        
        capsuleShape     = new CapsuleCollisionShape(1.1f, 3.1f, 1);
        
       //capsuleShape.
        //characterControl = new PlayerControl(capsuleShape, 0.05f);
        
        characterControl = new CharacterControl(capsuleShape, 0.05f);
        
//      characterControl.getPhysicsSpace().addCollisionListener((PhysicsCollisionListener) characterControl);

        
        characterControl.setCollideWithGroups(group_1);
        characterControl.setCollisionGroup(group_1);

        
        
        characterControl.setJumpSpeed(20);
        
        characterControl.setFallSpeed(60);
        characterControl.setGravity(60);
        

        //add control
        characterModel.addControl(characterControl);
1 Like