Jump to content

Server-Side Collision's


Recommended Posts


I recently started looking into how it would be best to handle collisions in a multiplayer situation,

i notised there are a few threads on the subject, but all died out, so i desided to start a new one.

Using babylon on client-side, ofc, and node.js for server.


Multiplayer games normally load their maps + content server-side for a lot of reasons, collision checking among those, but the best way of doing it, i'm still not quite sure.. 


I have a few ideas on how it can be approached, my concerns are however game smoothness.

In this example, all scenes and objects within these scenes, respectively, are imported on the client-side from .babylon files, 
which means that, all possible objects a player can collide with is contained in these files, (no player / player / mob collision).

Scenes, now refered to as "map or maps".


At game start, players are put into an js object, 
each player is identified by a id, but the object also contains the player's xyz positions, y rotation, gameId and a map id, refering to which map the player is currently on.



var players = [];

function Player(){

    this.playerId = players.length;

    //Game Setup
    this.gameId = 0; //Id used to track a specific game
    this.mapId = 0; //map of the specific game

    //Current Position & Rotation
    this.pX = 0;
    this.pY = 0;
    this.pZ = 0;
    this.rY = 0;

//Server adds each player after they have been matched..
var addPlayer = function(args){

    var player = new Player();
        player.playerId = args.id;
        player.gameId = args.gameId;
        player.mapId = args.mapId;
        player.pX = args.startingX;
        player.pY = args.startingY;
        player.pZ = args.startingZ;
    players.push( player );

    return player;




Import each map on the server-side into a js object when the nodejs server is started.


var maps = [];

function Map(){

    this.mapId = maps.length;


//At nodejs server startup, load each map and all physical objects found inside the .babylon file (incomplete)
var loadMap = function(args){

    var map = new Map();
        map.mapId = args.mapId;
    maps.push( map );

 (I haven't got the code to load maps into the object yet)

Each map should have a global id that is used for both client and server-side,

i.e. first map could be called 1.babylon, second map 2.babylon, and respectively the id's would be 1 and 2.
Those id's can then be used to identify which data inside the maps object to use when checking collisions..
    (client-side map loading example, player requests information from server, sever returns map id, BABYLON.SceneLoader.ImportMesh("", "assets/scenes/", +mapId+".babylon", scene, function (newMeshes) ) 


Example 1:(very high server load, but impossible for the player to cheat others than himself)

//update loop
Server sends all players positions, to all clients within the same game, every xx ms.

Player sends a movement requests to the server.
Server calculates next position and checks the maps object if the calculated position is possible, i.e. is the height increase from previous location to new locations too large(i.e. the player is running against a wall).
Server changes the player's position to the new position(in the player object) if the player didn't collide with anything and it is then sent to all players via the update loop.


Example 2:(low server load, but less secure) //player can disable collision and tamper with movement speeds, etc and still might not be caught.

//update loop
Server sends all players positions, to all clients within the same game, every xx ms.

Player calculates movement and collision on the client-side, sends data to server.
Server updates the player object with the players position.
Server makes random checks if a player's movement is possible (i.e. 1/10 of all requests the server recieves or (something like..) every 50'th request for each player)



I tried to reduce it as much as possible to only contain information related to collisions, if i left anything unanswered or seemed to forget something important, please let me know..

What are your thoughts on this/these approaches? Would it be possible? Better ideas as to how it can be done?


Link to comment
Share on other sites

Hi again aW!  Sorry that you are not getting responses.  You might want to check-out http://dailyjs.com/2015/03/20/scenevr/

I have asked about "world serving" in The Wingnut Chronicles thread... but I received the same response as you have gotten (crickets chirping).  :D

Notice that the SceneVR server... also boots a CannonJS physics engine on the server-side.  A user named @dbawel once talked about that same thing.  It might be worthwhile to dig into some of his posts.  I'm quite sure @Dad72 has some serious experience with "serving", too.  And, a forum search for 'server' and 'multiplayer' might return something useful, as well. 

Things like "serving webGL" and "webGL multiplayer" might be good searches to do... on the web itself.  In many ways, the server is a separate entity from the scene graph... and from the framework that fills that graph.  I can foresee a day when... a server might work with MANY kinds of client-side frameworks... considering you will be serving each user's startup scene.  Your server could actually ORDER the client-side to use whatever framework you choose... and use your choice of fallback options.

If you choose to make the client-side do repeated "packet pulls" for example, then YOU would install the packet-pulling code... into the user's client... when they first log-in.  You, as the server-meister (world archwizard), call the shots.  *shrug*  Here is another good web search.

Interesting topic, and an interesting post from you!  I wish I knew more about it... so I could speak intelligently with you.

Come to think of it, even if I DID know more about it, I probably couldn't speak intelligently.  :D  Good luck. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...