E
E
Egorian2018-10-03 20:32:15
Node.js
Egorian, 2018-10-03 20:32:15

Is physics handled correctly on the server?

I use phaser+nodejs+socketio+matterjs.
I run the following code on the server:

t=setInterval(function(){
        Matter.Engine.update(engine, engine.timing.delta);
    },1000/60)
socket.on("getBlock",function(){
        socket.emit("sendBlock",boxA.position)// положение какого-то блока. 
    });

On the client like this:
//phaser
function create(){
player = this.add.sprite(300,100, 'circle'); 
socket.on("sendBlock",function(blockPos){
  player.x=blockPos.x;
  player.y=blockPos.y;
});
}
function update(){
  socket.emit("getBlock");
}

An interval is launched on the server, where the physics is processed by the engine. Then the player makes a request through the sockets and receives the data and displays the actions in the game. Have I implemented the data transfer system correctly? Or should it be somehow different?
When I did the opposite, so that the server sends data without the request of the player, the client had slowdowns

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2018-10-03
@Egorian

https://habr.com/post/302394/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question