Bricktheworld Posted November 19, 2017 Share Posted November 19, 2017 Hello everyone! I am making a multiplayer game where I need to load players on demand whenever they come into the game. I have tried searching for hours but nothing seems to be working, so I came here. The closest thing to what I need was from here but it still doesn't really work for me and here's why. I need to clone a mesh on //called when a new player other than yourself joins socket.on('New Player', function(data) { }); and on //list of current players when you first join socket.on('listoplayers', function(data) { }); I have loaded the player mesh in an assetsManager and I would like to clone this mesh in these functions. Is there a way to this or a way around doing this? Also, here is the playground from the other topic: http://www.babylonjs-playground.com/#8XUNI%234 Hopefully, I explained that properly and if not, I'll explain in the comments. Thank you! Quote Link to comment Share on other sites More sharing options...
Raggar Posted November 19, 2017 Share Posted November 19, 2017 Something like this?: http://www.babylonjs-playground.com/#8XUNI#5 I pushed the loaded mesh into a global array. This way, the mesh can be called from any function outside the createScene, successCallback etc. functions. (For instance, in your socket events). I assume your players don't connect until After the scene has loaded, but you could simply check whether or not the model is populated in the array. If not, then load it (again). It does look like the clone function automatically enables the mesh, so no need to setEnable(true). Quote Link to comment Share on other sites More sharing options...
Bricktheworld Posted November 19, 2017 Author Share Posted November 19, 2017 Thank you! This is what I need. Problem is that when I move cloneMesh(); outside of the successCallback it gives me an error that it cannot clone property of undefined. How should I get around this? Quote Link to comment Share on other sites More sharing options...
Raggar Posted November 20, 2017 Share Posted November 20, 2017 If it's undefined, it might mean that the model hasn't been loaded yet. Make sure all models have been loaded before allowing players to join. Quote Link to comment Share on other sites More sharing options...
Bricktheworld Posted November 20, 2017 Author Share Posted November 20, 2017 Ohh! I get it now! Thank you I think I know what I need to do Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.