Search Unity

Question Deformation terrain in multiplayer

Discussion in 'Multiplayer' started by Zimaell, Mar 31, 2023.

  1. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    408
    I need to deform the surface, for example, the characters will dig the ground and thereby increase the depth, while all this is over the network.

    although I don’t make the world in 3D like in minecraft, that is, it’s an ordinary terrain that can be deformed during the game.

    But here the question is - how to deform the terrain during the game, how to save it, while also deforming it in others? How can I do that? Or are there other options for this task?

    Add: I found a video where exactly what I need

    tell me how to do it? (I think the terrain itself can be saved and transferred to others over the network)
     
    Last edited: Mar 31, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,870
    As far as I know, Terrain deformation works the same way as in the editor with "brush" operations that modify the terrain mesh such as "decrease height by y at position p with radius r". Something like that. This is the info you need to send via ServerRPC to the server, who then confirms or denies the change, and if confirmed, all clients execute that brush operation.

    Check the Terrain API: https://docs.unity3d.com/ScriptReference/Terrain.html
    You probably want to look for a tutorial for that.
    If you're not using Unity's terrain refer to the documentation of the terrain engine you are using.

    You can either transfer the entire terrain mesh (terrain data) or if the number of terrain mesh changes are limited you could record all brush operations and send a list of brush operations since the start of the server to any new clients. But that only makes sense if the size of the brush operations buffer is less than that of the terrain mesh.

    Note: one are where terrain deformation for multiplayer gets complex is collision resolution. Say, someone adds or removes a big chunk of terrain just where some other player is standing. What should happen with that other player? He must not fall out of the world, and he probably shouldn't fall to his death either.

    Also, how far would you allow players to deform the terrain? You will have to put in some limits, and it should be less than "the sky" and more than "all the way down to hell". ;)
     
  3. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    408
    at the expense of borders, I already thought, at the expense of deformation so that it does not affect other players, I also have an idea - just where you need to make a hole, for example, first a solid body (invisible) rises from below, the ground is removed under it by level, then this the body goes down, that's not the problem...

    I also sort of found the solution I needed, partially, now I'm thinking of applying it myself

    it remains to understand how to save the entire mesh (terrain), save it as a file, or combine all the vertices into a text field...
     
  4. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    408
    oh yes, the plane is shown in the saw, but it can also be applied to the terrain, I think ...