Synchronising vehicle - jme physics networking

Hello



I am trying to synchronise the car from the jme physics test between a server and a client using jme physics networking based on the flagrush example.



The problem is that the remote car is behaving strangely, losing its structure, like the wheels are not connected to the car.



I am using a custom SynchronizeMessage class and a custom controller.

The message incudes values for localTranslation, localRotation, linear and angular velocity for the chassi, suspension bases and wheels.



What am i missing?



screenshot attached

How should we know what you're missing, you dont show us your code :wink:

I am quite sure the problem is in the method that creates the car on the client side.

well here is the code:



the parent class for the server and client


public class CarParent implements SyncObjectManager{

    private Node scene;
    final carGame app = new carGame();

    public void setScene(Node scene) {
        this.scene = scene;
    }

    public Object create(SynchronizeCreateMessage scm) {
        System.out.println("Adding player");
        return buildRemotePlayer();
    }

    public boolean remove(SynchronizeRemoveMessage srm, Object obj) {
        SimpleCar box = (SimpleCar) obj;
        System.out.println("Removing player " + box.getName());
        return box.removeFromParent();
    }

    private Object buildRemotePlayer() {
        SimpleCar carNode = new SimpleCar(app.getThisPhysicsSpace());

        scene.attachChild(carNode);
        carNode.setPosition(0, 50, 0);

        scene.updateGeometricState(0, true);
        carNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
        scene.updateRenderState();
        return carNode;

    }



server:


public class CarServer extends CarParent {

    public CarServer() throws Exception{
        //start game in new thread
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        new Thread() {

            @Override
            public void run() {
                app.start();
            }
        }.start();

        //initialize networking
        InetSocketAddress serverReliable = new InetSocketAddress(InetAddress.getLocalHost(), 1500);
        InetSocketAddress serverFast = new InetSocketAddress(InetAddress.getLocalHost(), 1501);
        //this is our primary server and the addresses it should use
        JGNServer server = new JGNServer(serverReliable, serverFast);

        JMEPhysicsGraphicalSimpleCarController controller = new JMEPhysicsGraphicalSimpleCarController();

        SynchronizationManager syncManager = new SynchronizationManager(server, controller); //create the server that will send and receive sync messages
        syncManager.addSyncObjectManager(this);

        JGN.createThread(server).start(); //create a new thread for the server and start it
        JGN.createThread(syncManager).start(); //create and start a thread for the synchronization manager

        //getlocal player from game
        Field field = carGame.class.getDeclaredField("playerNode");
        field.setAccessible(true);
        SimpleCar player = null;
        while ((player = (SimpleCar) field.get(app)) == null) {
            try {
                Thread.sleep(100);
            } catch (Exception e) {
                System.err.println("Error while thread sleeping to get field:");
                e.printStackTrace();
            }
        }
        //get rootNode from the game
        field = carGame.class.getDeclaredField("scene");
        field.setAccessible(true);
        Node scene = (Node) field.get(app);
        setScene(scene);

        //register the server's box player
        syncManager.register(player, new SynchronizeCreateMessage(), 50);
    }

    public static void main(String[] args) throws Exception {
        new CarServer();

    }



client


public class CarClient extends CarParent{

    public CarClient() throws Exception{
        //start game in new thread
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        new Thread() {

            @Override
            public void run() {
                app.start();
            }
        }.start();

        //initialize networking
        //server addresses
        InetSocketAddress serverReliable = new InetSocketAddress(InetAddress.getByName("10.1.5.110"), 1500);
        InetSocketAddress serverFast = new InetSocketAddress(InetAddress.getByName("10.1.5.110"), 1501);
        //client addresses
        InetSocketAddress clientReliable = new InetSocketAddress(InetAddress.getLocalHost(), 0); //let Java choose a port for us
        InetSocketAddress clientFast = new InetSocketAddress(InetAddress.getLocalHost(), 0); //let Java choose a port for us
        //create the client and start it in its own thread
        JGNClient client = new JGNClient(clientReliable, clientFast); //create the networking client
        JGN.createThread(client).start(); //create a new thread for the client and start it

        JMEPhysicsGraphicalSimpleCarController controller = new JMEPhysicsGraphicalSimpleCarController();
//        JMEPhysicsGraphicalController controller = new JMEPhysicsGraphicalController();

        SynchronizationManager syncManager = new SynchronizationManager(client, controller); //create the server that will send and receive sync messages
        syncManager.addSyncObjectManager(this);

        JGN.createThread(syncManager).start(); //create and start a thread for the synchronization manager

        //getlocal player from game
        Field field = carGame.class.getDeclaredField("playerNode");
        field.setAccessible(true);
        SimpleCar player = null;
        while ((player = (SimpleCar) field.get(app)) == null) {
            try {
                Thread.sleep(100);
            } catch (Exception e) {
                System.err.println("Error while thread sleeping to get field:");
                e.printStackTrace();
            }
        }
        //get rootNode from the game
        field = carGame.class.getDeclaredField("scene");
        field.setAccessible(true);
        Node scene = (Node) field.get(app);
        setScene(scene);

        //connect to the server
        System.out.println("Connecting...");
        client.connectAndWait(serverReliable, serverFast, 5000);
        System.out.println("Connected!");

        client.getServerConnection().getReliableClient().addMessageListener(new MessageListener() {

            public void messageCertified(Message message) {
                System.out.println("Message Certified: " + message);
            }

            public void messageFailed(Message message) {
                System.out.println("Message Failed: " + message);
            }

            public void messageReceived(Message message) {
                System.out.println("Message Received: " + message);
            }

            public void messageSent(Message message) {
                System.out.println("Message Sent: " + message);
            }
        });

        syncManager.register(player, new SynchronizeCreateMessage(), 50);

    }

    public static void main(String[] args) throws Exception {
        new CarClient();

    }

}



and controller


public class JMEPhysicsGraphicalSimpleCarController implements GraphicalController<SimpleCar> {

    private Vector3f store;

    public JMEPhysicsGraphicalSimpleCarController(){
        store = new Vector3f();
    }

    public void applySynchronizationMessage(SynchronizeMessage message, SimpleCar car) {
        SynchronizeSimpleCarMessage m = (SynchronizeSimpleCarMessage) message;
        car.getChassis().clearDynamics();
        car.getFrontSuspension().getLeftBase().clearDynamics();
        car.getFrontSuspension().getLeftBase().clearDynamics();
        car.getRearSuspension().getLeftBase().clearDynamics();
        car.getRearSuspension().getRightBase().clearDynamics();
        car.getFrontSuspension().getLeftWheel().getPhysicsNode().clearDynamics();
        car.getFrontSuspension().getRightWheel().getPhysicsNode().clearDynamics();
        car.getRearSuspension().getLeftWheel().getPhysicsNode().clearDynamics();
        car.getRearSuspension().getRightWheel().getPhysicsNode().clearDynamics();

        //chassi
        car.getChassis().setLocalTranslation(m.getChassiPositionX(), m.getChassiPositionY(), m.getChassiPositionZ());
        car.getChassis().setLocalRotation(new Quaternion(m.getChassiRotationX(), m.getChassiRotationY(), m.getChassiRotationY(), m.getChassiRotationW()));
        car.getChassis().setAngularVelocity(new Vector3f(m.getChassiAngularX(), m.getChassiAngularY(), m.getChassiAngularZ()));
        car.getChassis().setLinearVelocity(new Vector3f(m.getChassiLinearX(), m.getChassiLinearY(), m.getChassiAngularZ()));
       
        //front suspension left base
        car.getFrontSuspension().getLeftBase().setLocalTranslation(m.getSuspBaseFLPositionX(), m.getSuspBaseFLPositionY(), m.getSuspBaseFLPositionZ());
        car.getFrontSuspension().getLeftBase().setLocalRotation(new Quaternion(m.getSuspBaseFLRotationX(), m.getSuspBaseFLRotationY(), m.getSuspBaseFLRotationZ(), m.getSuspBaseFLRotationW()));
        car.getFrontSuspension().getLeftBase().setLinearVelocity(new Vector3f(m.getSuspBaseFLLinearX(), m.getSuspBaseFLLinearY(), m.getSuspBaseFLLinearZ()));
        car.getFrontSuspension().getLeftBase().setAngularVelocity(new Vector3f(m.getSuspBaseFLAngularX(), m.getSuspBaseFLAngularY(), m.getSuspBaseFLAngularZ()));

        //rear suspension left base
        car.getRearSuspension().getLeftBase().setLocalTranslation(m.getSuspBaseBLPositionX(), m.getSuspBaseBLPositionY(), m.getSuspBaseBLPositionZ());
        car.getRearSuspension().getLeftBase().setLocalRotation(new Quaternion(m.getSuspBaseBLRotationX(), m.getSuspBaseBLRotationY(), m.getSuspBaseBLRotationZ(), m.getSuspBaseBLRotationW()));
        car.getRearSuspension().getLeftBase().setLinearVelocity(new Vector3f(m.getSuspBaseBLLinearX(), m.getSuspBaseBLLinearY(), m.getSuspBaseBLLinearZ()));
        car.getRearSuspension().getLeftBase().setAngularVelocity(new Vector3f(m.getSuspBaseBLAngularX(), m.getSuspBaseBLAngularY(), m.getSuspBaseBLAngularZ()));

        //front suspension rigth base
        car.getFrontSuspension().getRightBase().setLocalTranslation(m.getSuspBaseFRPositionX(), m.getSuspBaseFRPositionY(), m.getSuspBaseFRPositionZ());
        car.getFrontSuspension().getRightBase().setLocalRotation(new Quaternion(m.getSuspBaseFRRotationX(), m.getSuspBaseFRRotationY(), m.getSuspBaseFRRotationZ(), m.getSuspBaseFRRotationW()));
        car.getFrontSuspension().getRightBase().setLinearVelocity(new Vector3f(m.getSuspBaseFRLinearX(), m.getSuspBaseFRLinearY(), m.getSuspBaseFRLinearZ()));
        car.getFrontSuspension().getRightBase().setAngularVelocity(new Vector3f(m.getSuspBaseFRAngularX(), m.getSuspBaseFRAngularY(), m.getSuspBaseFRAngularZ()));

        //rear suspension right base
        car.getRearSuspension().getRightBase().setLocalTranslation(m.getSuspBaseBRPositionX(), m.getSuspBaseBRPositionY(), m.getSuspBaseBRPositionZ());
        car.getRearSuspension().getRightBase().setLocalRotation(new Quaternion(m.getSuspBaseBRRotationX(), m.getSuspBaseBRRotationY(), m.getSuspBaseBRRotationZ(), m.getSuspBaseBRRotationW()));
        car.getRearSuspension().getRightBase().setLinearVelocity(new Vector3f(m.getSuspBaseBRLinearX(), m.getSuspBaseBRLinearY(), m.getSuspBaseBRLinearZ()));
        car.getRearSuspension().getRightBase().setAngularVelocity(new Vector3f(m.getSuspBaseBRAngularX(), m.getSuspBaseBRAngularY(), m.getSuspBaseBRAngularZ()));

        //front suspension left wheel
        car.getFrontSuspension().getLeftWheel().getPhysicsNode().setLocalTranslation(m.getWheelFLPositionX(), m.getWheelFLPositionY(), m.getWheelFLPositionZ());
        car.getFrontSuspension().getLeftWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelFLRotationX(), m.getWheelFLRotationY(), m.getWheelFLRotationZ(), m.getWheelFLRotationW()));
        car.getFrontSuspension().getLeftWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelFLLinearX(), m.getWheelFLLinearY(), m.getWheelFLLinearZ()));
        car.getFrontSuspension().getLeftWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelFLAngularX(), m.getWheelFLAngularY(), m.getWheelFLAngularZ()));

        //rear suspension left wheel
        car.getRearSuspension().getLeftWheel().getPhysicsNode().setLocalTranslation(m.getWheelBLPositionX(), m.getWheelBLPositionY(), m.getWheelBLPositionZ());
        car.getRearSuspension().getLeftWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelBLRotationX(), m.getWheelBLRotationY(), m.getWheelBLRotationZ(), m.getWheelBLRotationW()));
        car.getRearSuspension().getLeftWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelBLLinearX(), m.getWheelBLLinearY(), m.getWheelBLLinearZ()));
        car.getRearSuspension().getLeftWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelBLAngularX(), m.getWheelBLAngularY(), m.getWheelBLAngularZ()));

        //front suspension rigth wheel
        car.getFrontSuspension().getRightWheel().getPhysicsNode().setLocalTranslation(m.getWheelFRPositionX(), m.getWheelFRPositionY(), m.getWheelFRPositionZ());
        car.getFrontSuspension().getRightWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelFRRotationX(), m.getWheelFRRotationY(), m.getWheelFRRotationZ(), m.getWheelFRRotationW()));
        car.getFrontSuspension().getRightWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelFRLinearX(), m.getWheelFRLinearY(), m.getWheelFRLinearZ()));
        car.getFrontSuspension().getRightWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelFRAngularX(), m.getWheelFRAngularY(), m.getWheelFRAngularZ()));

        //rear suspension right wheel
        car.getRearSuspension().getRightWheel().getPhysicsNode().setLocalTranslation(m.getWheelBRPositionX(), m.getWheelBRPositionY(), m.getWheelBRPositionZ());
        car.getRearSuspension().getRightWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelBRRotationX(), m.getWheelBRRotationY(), m.getWheelBRRotationZ(), m.getWheelBRRotationW()));
        car.getRearSuspension().getRightWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelBRLinearX(), m.getWheelBRLinearY(), m.getWheelBRLinearZ()));
        car.getRearSuspension().getRightWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelBRAngularX(), m.getWheelBRAngularY(), m.getWheelBRAngularZ()));

    }

    public SynchronizeMessage createSynchronizationMessage(SimpleCar car) {
        SynchronizeSimpleCarMessage m = new SynchronizeSimpleCarMessage();

        //chassi
        m.setChassiPositionX(car.getChassis().getLocalTranslation().getX());
        m.setChassiPositionY(car.getChassis().getLocalTranslation().getY());
        m.setChassiPositionZ(car.getChassis().getLocalTranslation().getZ());
        m.setChassiRotationX(car.getChassis().getLocalRotation().getX());
        m.setChassiRotationY(car.getChassis().getLocalRotation().getY());
        m.setChassiRotationZ(car.getChassis().getLocalRotation().getZ());
        m.setChassiRotationW(car.getChassis().getLocalRotation().getW());
        car.getChassis().getAngularVelocity(store);
        m.setChassiAngularX(store.getX());
        m.setChassiAngularY(store.getY());
        m.setChassiAngularZ(store.getZ());
        car.getChassis().getLinearVelocity(store);
        m.setChassiLinearX(store.getX());
        m.setChassiLinearY(store.getY());
        m.setChassiLinearZ(store.getZ());

        //front suspension left base
        m.setSuspBaseFLPositionX(car.getFrontSuspension().getLeftBase().getLocalTranslation().getX());
        m.setSuspBaseFLPositionY(car.getFrontSuspension().getLeftBase().getLocalTranslation().getY());
        m.setSuspBaseFLPositionZ(car.getFrontSuspension().getLeftBase().getLocalTranslation().getZ());
        m.setSuspBaseFLRotationX(car.getFrontSuspension().getLeftBase().getLocalRotation().getX());
        m.setSuspBaseFLRotationY(car.getFrontSuspension().getLeftBase().getLocalRotation().getY());
        m.setSuspBaseFLRotationZ(car.getFrontSuspension().getLeftBase().getLocalRotation().getZ());
        m.setSuspBaseFLRotationW(car.getFrontSuspension().getLeftBase().getLocalRotation().getW());
        car.getFrontSuspension().getLeftBase().getAngularVelocity(store);
        m.setSuspBaseFLAngularX(store.getX());
        m.setSuspBaseFLAngularY(store.getY());
        m.setSuspBaseFLAngularZ(store.getZ());
        car.getFrontSuspension().getLeftBase().getLinearVelocity(store);
        m.setSuspBaseFLLinearX(store.getX());
        m.setSuspBaseFLLinearY(store.getY());
        m.setSuspBaseFLLinearZ(store.getZ());

        //front suspension right base
        m.setSuspBaseFRPositionX(car.getFrontSuspension().getRightBase().getLocalTranslation().getX());
        m.setSuspBaseFRPositionY(car.getFrontSuspension().getRightBase().getLocalTranslation().getY());
        m.setSuspBaseFRPositionZ(car.getFrontSuspension().getRightBase().getLocalTranslation().getZ());
        m.setSuspBaseFRRotationX(car.getFrontSuspension().getRightBase().getLocalRotation().getX());
        m.setSuspBaseFRRotationY(car.getFrontSuspension().getRightBase().getLocalRotation().getY());
        m.setSuspBaseFRRotationZ(car.getFrontSuspension().getRightBase().getLocalRotation().getZ());
        m.setSuspBaseFRRotationW(car.getFrontSuspension().getRightBase().getLocalRotation().getW());
        car.getFrontSuspension().getRightBase().getAngularVelocity(store);
        m.setSuspBaseFRAngularX(store.getX());
        m.setSuspBaseFRAngularY(store.getY());
        m.setSuspBaseFRAngularZ(store.getZ());
        car.getFrontSuspension().getRightBase().getLinearVelocity(store);
        m.setSuspBaseFRLinearX(store.getX());
        m.setSuspBaseFRLinearY(store.getY());
        m.setSuspBaseFRLinearZ(store.getZ());

        //rear suspension left base
        m.setSuspBaseBLPositionX(car.getRearSuspension().getLeftBase().getLocalTranslation().getX());
        m.setSuspBaseBLPositionY(car.getRearSuspension().getLeftBase().getLocalTranslation().getY());
        m.setSuspBaseBLPositionZ(car.getRearSuspension().getLeftBase().getLocalTranslation().getZ());
        m.setSuspBaseBLRotationX(car.getRearSuspension().getLeftBase().getLocalRotation().getX());
        m.setSuspBaseBLRotationY(car.getRearSuspension().getLeftBase().getLocalRotation().getY());
        m.setSuspBaseBLRotationZ(car.getRearSuspension().getLeftBase().getLocalRotation().getZ());
        m.setSuspBaseBLRotationW(car.getRearSuspension().getLeftBase().getLocalRotation().getW());
        car.getRearSuspension().getLeftBase().getAngularVelocity(store);
        m.setSuspBaseBLAngularX(store.getX());
        m.setSuspBaseBLAngularY(store.getY());
        m.setSuspBaseBLAngularZ(store.getZ());
        car.getRearSuspension().getLeftBase().getLinearVelocity(store);
        m.setSuspBaseBLLinearX(store.getX());
        m.setSuspBaseBLLinearY(store.getY());
        m.setSuspBaseBLLinearZ(store.getZ());

        //rear suspension right base
        m.setSuspBaseBRPositionX(car.getRearSuspension().getRightBase().getLocalTranslation().getX());
        m.setSuspBaseBRPositionY(car.getRearSuspension().getRightBase().getLocalTranslation().getY());
        m.setSuspBaseBRPositionZ(car.getRearSuspension().getRightBase().getLocalTranslation().getZ());
        m.setSuspBaseBRRotationX(car.getRearSuspension().getRightBase().getLocalRotation().getX());
        m.setSuspBaseBRRotationY(car.getRearSuspension().getRightBase().getLocalRotation().getY());
        m.setSuspBaseBRRotationZ(car.getRearSuspension().getRightBase().getLocalRotation().getZ());
        m.setSuspBaseBRRotationW(car.getRearSuspension().getRightBase().getLocalRotation().getW());
        car.getRearSuspension().getRightBase().getAngularVelocity(store);
        m.setSuspBaseBRAngularX(store.getX());
        m.setSuspBaseBRAngularY(store.getY());
        m.setSuspBaseBRAngularZ(store.getZ());
        car.getRearSuspension().getRightBase().getLinearVelocity(store);
        m.setSuspBaseBRLinearX(store.getX());
        m.setSuspBaseBRLinearY(store.getY());
        m.setSuspBaseBRLinearZ(store.getZ());
       
        //front suspension left wheel
        m.setWheelFLPositionX(car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLocalTranslation().getX());
        m.setWheelFLPositionY(car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLocalTranslation().getY());
        m.setWheelFLPositionZ(car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLocalTranslation().getZ());
        m.setWheelFLRotationX(car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getX());
        m.setWheelFLRotationY(car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getY());
        m.setWheelFLRotationZ(car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getZ());
        m.setWheelFLRotationW(car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getW());
        car.getFrontSuspension().getLeftWheel().getPhysicsNode().getAngularVelocity(store);
        m.setWheelFLAngularX(store.getX());
        m.setWheelFLAngularY(store.getY());
        m.setWheelFLAngularZ(store.getZ());
        car.getFrontSuspension().getLeftWheel().getPhysicsNode().getLinearVelocity(store);
        m.setWheelFLLinearX(store.getX());
        m.setWheelFLLinearY(store.getY());
        m.setWheelFLLinearZ(store.getZ());

        //front suspension right wheel
        m.setWheelFRPositionX(car.getFrontSuspension().getRightWheel().getPhysicsNode().getLocalTranslation().getX());
        m.setWheelFRPositionY(car.getFrontSuspension().getRightWheel().getPhysicsNode().getLocalTranslation().getY());
        m.setWheelFRPositionZ(car.getFrontSuspension().getRightWheel().getPhysicsNode().getLocalTranslation().getZ());
        m.setWheelFRRotationX(car.getFrontSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getX());
        m.setWheelFRRotationY(car.getFrontSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getY());
        m.setWheelFRRotationZ(car.getFrontSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getZ());
        m.setWheelFRRotationW(car.getFrontSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getW());
        car.getFrontSuspension().getRightWheel().getPhysicsNode().getAngularVelocity(store);
        m.setWheelFRAngularX(store.getX());
        m.setWheelFRAngularY(store.getY());
        m.setWheelFRAngularZ(store.getZ());
        car.getFrontSuspension().getRightWheel().getPhysicsNode().getLinearVelocity(store);
        m.setWheelFRLinearX(store.getX());
        m.setWheelFRLinearY(store.getY());
        m.setWheelFRLinearZ(store.getZ());

        //rear suspension left wheel
        m.setWheelBLPositionX(car.getRearSuspension().getLeftWheel().getPhysicsNode().getLocalTranslation().getX());
        m.setWheelBLPositionY(car.getRearSuspension().getLeftWheel().getPhysicsNode().getLocalTranslation().getY());
        m.setWheelBLPositionZ(car.getRearSuspension().getLeftWheel().getPhysicsNode().getLocalTranslation().getZ());
        m.setWheelBLRotationX(car.getRearSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getX());
        m.setWheelBLRotationY(car.getRearSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getY());
        m.setWheelBLRotationZ(car.getRearSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getZ());
        m.setWheelBLRotationW(car.getRearSuspension().getLeftWheel().getPhysicsNode().getLocalRotation().getW());
        car.getRearSuspension().getLeftWheel().getPhysicsNode().getAngularVelocity(store);
        m.setWheelBLAngularX(store.getX());
        m.setWheelBLAngularY(store.getY());
        m.setWheelBLAngularZ(store.getZ());
        car.getRearSuspension().getLeftWheel().getPhysicsNode().getLinearVelocity(store);
        m.setWheelBLLinearX(store.getX());
        m.setWheelBLLinearY(store.getY());
        m.setWheelBLLinearZ(store.getZ());

        //rear suspension right wheel
        m.setWheelBRPositionX(car.getRearSuspension().getRightWheel().getPhysicsNode().getLocalTranslation().getX());
        m.setWheelBRPositionY(car.getRearSuspension().getRightWheel().getPhysicsNode().getLocalTranslation().getY());
        m.setWheelBRPositionZ(car.getRearSuspension().getRightWheel().getPhysicsNode().getLocalTranslation().getZ());
        m.setWheelBRRotationX(car.getRearSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getX());
        m.setWheelBRRotationY(car.getRearSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getY());
        m.setWheelBRRotationZ(car.getRearSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getZ());
        m.setWheelBRRotationW(car.getRearSuspension().getRightWheel().getPhysicsNode().getLocalRotation().getW());
        car.getRearSuspension().getRightWheel().getPhysicsNode().getAngularVelocity(store);
        m.setWheelBRAngularX(store.getX());
        m.setWheelBRAngularY(store.getY());
        m.setWheelBRAngularZ(store.getZ());
        car.getRearSuspension().getRightWheel().getPhysicsNode().getLinearVelocity(store);
        m.setWheelBRLinearX(store.getX());
        m.setWheelBRLinearY(store.getY());
        m.setWheelBRLinearZ(store.getZ());

        return m;
    }

    /**
     * This method will always return 1.0f. It is recommended to override this method
     * in games to provide better efficiency to synchronization.
     */
    public float proximity(SimpleCar dpn, short playerId) {
        return 1.0f;
    }

    /**
     * This method will always return true. It is recommended to override this method
     * in games to provide a layer of security.
     */
    public boolean validateMessage(SynchronizeMessage message, SimpleCar dpn) {
        return true;
    }

    public boolean validateCreate(SynchronizeCreateMessage message) {
        return true;
    }

    public boolean validateRemove(SynchronizeRemoveMessage message) {
        return true;
    }
}

Ok, first of all the way the JGN demo implementation does the syncing is not very good. The network thread just blindly sets and changes the values of physics and scenegraph objects. This is not good since the opengl render loop and the physics are running on another thread and using these values as well, which is certain to result in problems sooner or later. You should use the GameTaskQueueManager to do the syncing on the right thread.

Other than that I also can't see the problem right now, I suppose the client and server use the same SimpleCar class so they should have the same joints etc.

It seems reasonable that this might be the problem.



The strange thing is that with the same setup but a box instead of the car and the default jme-physics-networking, JMEPhysicsGraphicalController works fine, so i thought the problem was maybe in my implementation of the graphical controller.



I will search about the GameTaskQueueManager myself but since I am new to jme I would appreciate an example using GameTaskQueueManager in networking or a link (wiki or another thread).



thanks for your time :slight_smile:

Its basically just a queue of callables, you can use it like this:


        GameTaskQueueManager.getManager().update(new Callable<Void>() {
            public Void call() throws Exception {
                //do stuff here
                return null;
            }
        } );

If I get this right everything inside the call method updates in the thread that contains the scene and the physics?



So I changed the graphical controller class putting everything in the applySynchronizationMessage inside the call method.



That doesn't fix the original problem and it also crates a new one.

Before, the client and the server could see the remote car in the correct location (location seemed synchronised) but the car was not how it was meant to be, like in the screenshot.

Now, only the server can see client's car in the correct location. The client sees the server's car in the spawning location and it never moves. And the cars remains messed up.  :frowning:



the applySynchronizationMessage in my graphical controller class:


public void applySynchronizationMessage(SynchronizeMessage message, final SimpleCar car) {
        final SynchronizeSimpleCarMessage m = (SynchronizeSimpleCarMessage) message;

        GameTaskQueueManager.getManager().update(new Callable<Void>() {

            public Void call() throws Exception {

                car.getChassis().clearDynamics();
                car.getFrontSuspension().getLeftBase().clearDynamics();
                car.getFrontSuspension().getLeftBase().clearDynamics();
                car.getRearSuspension().getLeftBase().clearDynamics();
                car.getRearSuspension().getRightBase().clearDynamics();
                car.getFrontSuspension().getLeftWheel().getPhysicsNode().clearDynamics();
                car.getFrontSuspension().getRightWheel().getPhysicsNode().clearDynamics();
                car.getRearSuspension().getLeftWheel().getPhysicsNode().clearDynamics();
                car.getRearSuspension().getRightWheel().getPhysicsNode().clearDynamics();

                //chassi
                car.getChassis().setLocalTranslation(m.getChassiPositionX(), m.getChassiPositionY(), m.getChassiPositionZ());
                car.getChassis().setLocalRotation(new Quaternion(m.getChassiRotationX(), m.getChassiRotationY(), m.getChassiRotationY(), m.getChassiRotationW()));
                car.getChassis().setAngularVelocity(new Vector3f(m.getChassiAngularX(), m.getChassiAngularY(), m.getChassiAngularZ()));
                car.getChassis().setLinearVelocity(new Vector3f(m.getChassiLinearX(), m.getChassiLinearY(), m.getChassiAngularZ()));

                //front suspension left base
                car.getFrontSuspension().getLeftBase().setLocalTranslation(m.getSuspBaseFLPositionX(), m.getSuspBaseFLPositionY(), m.getSuspBaseFLPositionZ());
                car.getFrontSuspension().getLeftBase().setLocalRotation(new Quaternion(m.getSuspBaseFLRotationX(), m.getSuspBaseFLRotationY(), m.getSuspBaseFLRotationZ(), m.getSuspBaseFLRotationW()));
                car.getFrontSuspension().getLeftBase().setLinearVelocity(new Vector3f(m.getSuspBaseFLLinearX(), m.getSuspBaseFLLinearY(), m.getSuspBaseFLLinearZ()));
                car.getFrontSuspension().getLeftBase().setAngularVelocity(new Vector3f(m.getSuspBaseFLAngularX(), m.getSuspBaseFLAngularY(), m.getSuspBaseFLAngularZ()));

                //rear suspension left base
                car.getRearSuspension().getLeftBase().setLocalTranslation(m.getSuspBaseBLPositionX(), m.getSuspBaseBLPositionY(), m.getSuspBaseBLPositionZ());
                car.getRearSuspension().getLeftBase().setLocalRotation(new Quaternion(m.getSuspBaseBLRotationX(), m.getSuspBaseBLRotationY(), m.getSuspBaseBLRotationZ(), m.getSuspBaseBLRotationW()));
                car.getRearSuspension().getLeftBase().setLinearVelocity(new Vector3f(m.getSuspBaseBLLinearX(), m.getSuspBaseBLLinearY(), m.getSuspBaseBLLinearZ()));
                car.getRearSuspension().getLeftBase().setAngularVelocity(new Vector3f(m.getSuspBaseBLAngularX(), m.getSuspBaseBLAngularY(), m.getSuspBaseBLAngularZ()));

                //front suspension rigth base
                car.getFrontSuspension().getRightBase().setLocalTranslation(m.getSuspBaseFRPositionX(), m.getSuspBaseFRPositionY(), m.getSuspBaseFRPositionZ());
                car.getFrontSuspension().getRightBase().setLocalRotation(new Quaternion(m.getSuspBaseFRRotationX(), m.getSuspBaseFRRotationY(), m.getSuspBaseFRRotationZ(), m.getSuspBaseFRRotationW()));
                car.getFrontSuspension().getRightBase().setLinearVelocity(new Vector3f(m.getSuspBaseFRLinearX(), m.getSuspBaseFRLinearY(), m.getSuspBaseFRLinearZ()));
                car.getFrontSuspension().getRightBase().setAngularVelocity(new Vector3f(m.getSuspBaseFRAngularX(), m.getSuspBaseFRAngularY(), m.getSuspBaseFRAngularZ()));

                //rear suspension right base
                car.getRearSuspension().getRightBase().setLocalTranslation(m.getSuspBaseBRPositionX(), m.getSuspBaseBRPositionY(), m.getSuspBaseBRPositionZ());
                car.getRearSuspension().getRightBase().setLocalRotation(new Quaternion(m.getSuspBaseBRRotationX(), m.getSuspBaseBRRotationY(), m.getSuspBaseBRRotationZ(), m.getSuspBaseBRRotationW()));
                car.getRearSuspension().getRightBase().setLinearVelocity(new Vector3f(m.getSuspBaseBRLinearX(), m.getSuspBaseBRLinearY(), m.getSuspBaseBRLinearZ()));
                car.getRearSuspension().getRightBase().setAngularVelocity(new Vector3f(m.getSuspBaseBRAngularX(), m.getSuspBaseBRAngularY(), m.getSuspBaseBRAngularZ()));

                //front suspension left wheel
                car.getFrontSuspension().getLeftWheel().getPhysicsNode().setLocalTranslation(m.getWheelFLPositionX(), m.getWheelFLPositionY(), m.getWheelFLPositionZ());
                car.getFrontSuspension().getLeftWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelFLRotationX(), m.getWheelFLRotationY(), m.getWheelFLRotationZ(), m.getWheelFLRotationW()));
                car.getFrontSuspension().getLeftWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelFLLinearX(), m.getWheelFLLinearY(), m.getWheelFLLinearZ()));
                car.getFrontSuspension().getLeftWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelFLAngularX(), m.getWheelFLAngularY(), m.getWheelFLAngularZ()));

                //rear suspension left wheel
                car.getRearSuspension().getLeftWheel().getPhysicsNode().setLocalTranslation(m.getWheelBLPositionX(), m.getWheelBLPositionY(), m.getWheelBLPositionZ());
                car.getRearSuspension().getLeftWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelBLRotationX(), m.getWheelBLRotationY(), m.getWheelBLRotationZ(), m.getWheelBLRotationW()));
                car.getRearSuspension().getLeftWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelBLLinearX(), m.getWheelBLLinearY(), m.getWheelBLLinearZ()));
                car.getRearSuspension().getLeftWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelBLAngularX(), m.getWheelBLAngularY(), m.getWheelBLAngularZ()));

                //front suspension rigth wheel
                car.getFrontSuspension().getRightWheel().getPhysicsNode().setLocalTranslation(m.getWheelFRPositionX(), m.getWheelFRPositionY(), m.getWheelFRPositionZ());
                car.getFrontSuspension().getRightWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelFRRotationX(), m.getWheelFRRotationY(), m.getWheelFRRotationZ(), m.getWheelFRRotationW()));
                car.getFrontSuspension().getRightWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelFRLinearX(), m.getWheelFRLinearY(), m.getWheelFRLinearZ()));
                car.getFrontSuspension().getRightWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelFRAngularX(), m.getWheelFRAngularY(), m.getWheelFRAngularZ()));

                //rear suspension right wheel
                car.getRearSuspension().getRightWheel().getPhysicsNode().setLocalTranslation(m.getWheelBRPositionX(), m.getWheelBRPositionY(), m.getWheelBRPositionZ());
                car.getRearSuspension().getRightWheel().getPhysicsNode().setLocalRotation(new Quaternion(m.getWheelBRRotationX(), m.getWheelBRRotationY(), m.getWheelBRRotationZ(), m.getWheelBRRotationW()));
                car.getRearSuspension().getRightWheel().getPhysicsNode().setLinearVelocity(new Vector3f(m.getWheelBRLinearX(), m.getWheelBRLinearY(), m.getWheelBRLinearZ()));
                car.getRearSuspension().getRightWheel().getPhysicsNode().setAngularVelocity(new Vector3f(m.getWheelBRAngularX(), m.getWheelBRAngularY(), m.getWheelBRAngularZ()));

                return null;
            }
        });
    }



the rest is the same as before

i include screenshots from the server and client side at the same time.
(on the client side the car seems ok but it isn't)

Do you use the latest svn version of JGN? I remember that there was a problem with the first player added being assigned a wrong number on the server which makes it not update correctly.

I have the latest versions of all projects required.



I tried a simpler example using insted of the vehicle from jme-physics example a node containing a dynamic physics node (dpn) box, 4 dpn spheres and joints connecting the spheres to the box, without any axis.

I noticed that the joint on the box on the remote "vehicle" is located where the "vehicle" should be on the x and z but not on y(hight). I will attach a screenshot tomorrow.



I might need to change my approach. :expressionless:

Spyd said:

I noticed that the joint on the box on the remote "vehicle" is located where the "vehicle" should be on the x and z but not on y(hight). I will attach a screenshot tomorrow.


attached the screenshot

I have this exact same problem.



Did you manage to solve it? Can you show the code, what was wrong?



Thank you.

ACtually, Why are you wanting a second vehicle clientside? Just place a dummy there with Kinematic mode (or none at all) and let the server handle the stuff.