Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How MMOs could feature much better physics than single player games [for programmers]

Discussion in 'General Discussion' started by kiriri, Jul 26, 2015.

  1. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    Hi,
    I'm currently developing a high quality cloth/hair physics system for massive multiplayer games. My initial thought was that if I could create really small abstracted hair/cloth datatypes and ensure all clients have a good ping, then I could just have the client calculate their own cloth/hair physics and then send it to both the server and directly to all peers (to avoid unnecessary lags), without using a server in between. That way each client only calculates their own character's physics (and downloads the physics results for all other characters around him). That way the game could feature dynamic clothes and hair on a detail and scale that would never be possible in single player games. My early tests are looking good, eg with characters being able to use realtime skinnedMesh vs hair collisions and sending them via less than 1kbit/s. (theoretical data transfer, might be slightly more in a reality due to networking errors etc)

    I want to ensure no one hacks the system. I do this by randomly doublechecking physics calculations on the server. If the server calculates a different result than the client, or if the result the client has sent to his peers is different than the result the client has sent to the server, the client is kicked from the server. However, since the client always sends his results to the server, it can never know when the server checks the result or not.

    Now I'm not the brightest person in the universe and I'm well aware of that . So I thought I'd show off my idea here before actually working on all the details this project would need. As far as I know it this has not been done before, and I don't understand why. Do you have any ideas what could / should go wrong? Any suggestions or comments? If I finalize this project I want to make it a portfolio project and I don't want to spend weeks or months on something that has obvious logical fallacies just because I didn't want to ask for help here :)

    Cheers,
    kiriri
     
    Last edited: Jul 26, 2015
  2. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Hm, idea itself is sound. However you don't always have certainity about client's ping, so "random checking" would need to have quite a bit of tolerance.
     
  3. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    The random checks do not need to be executed immediately. Even if it takes a second, after that second the server could determine whether the user calculated the correct result and kick him (or not). Eg if the hair system did not allow for hair physics to stretch hair strands beyond a certain distance, then the only thing hackers could do was to make their hair look weird for a second, and I think anyone can tolerate that much. They would not be able to scale up their hair to the size of the world and block out everyone's cameras or the like.
     
  4. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    Depends on what you call 'good ping'. If you can guarantee that all will have a ping of ~<15, it wouldn't be too bad. But if it gets anywhere near realistic (50-150+), you'll get wrecked by desync between body (server-client ping) and hair (client-client ping). Unless you make the body update via p2p as well, and random-check those updates, but I suppose that'll create some way harder problems in any authoritative MMO.
     
  5. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    You are right, I didn't think of that.
    p2p positional tracking could be possible if done like this :
    client1 sends positional data to client2 and server.
    client2 sends client1 ip/id and received positional data back to server.
    Server checks if the oldest value on a stack of client1s position is the position client2 has just sent. If it is, it removes that entry from the stack.
    If it's not the server will be able to revert all illegal changes client1 made.

    Now the downside is this is a lot more bandwidth - expensive, but compared to all the other things the server will have to do it should not really weigh that heavy I think. It may be more expensive than the usual client-server-client connection but it's one of the very few disadvantages.

    EDIT : Some other things like damage calculations must be done via the server though, but most things don't need to sync with the animations/physics/movement so it should be okay if they lag a bit
     
    Last edited: Jul 26, 2015
  6. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    If it has no impact on gameplay, then let it run on the client. Don't bother trying to shovel useless data down someone's pipe. Even if you think people's bandwidth is large enough, that doesn't mean it won't impact latency.
     
    angrypenguin and Kiwasi like this.
  7. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    Oh but physics have a huge impact on gameplay. If I look at mmos which have up to 100 people visible at a time, and I wanted to have realistic hair physics on all of them, I'd be at less than 1 fps. If I calculated the physics individually and only sent some bezier curve transformation info around, I could replicate the same effect at 30 or maybe even 60 fps.
    My target platform is VR PC so I think "gimmicks" like realistic hair and cloth simulations may really improve the sense of immersion and therefore improve the game as a whole.

    EDIT : also, this system does not exclude optional quality settings. If your network can't handle it, you would be able to disable it. Clients can keep a log on their peers so they only need to query once, there would be no additional cost if someone disabled physics.
     
  8. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    I'll reiterate; if players are not directly interacting with it collectively, then there is no reason for it to be done over the network. It is substantially easier to have physics run all of it at a higher frequency and with more detail while running purely on the client, than it will be to have some slow distributed computing scheme. Unless you are scared to death that someone will try their damnedest to get their hair to stick up, only to find that it doesn't appear that way to anyone else, then there is probably little value in it.
     
    Ony, Kiwasi and Deleted User like this.
  9. Deleted User

    Deleted User

    Guest

    Exactly as Rockodyne was saying, keep anything that's un-important on the client..
     
    Ony and Kiwasi like this.
  10. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    I don't think I understand you. Running realtime hair/cloth simulations in mmos is currently impossible. Actually, from what I can see it's impossible with any kind of silicon cpu, unless they get substantially bigger in the future. I cannot make it client side only, unless I bake the cloth/hair beforehand. Realtime hair simulation requires either bezier-mesh intersection or obb-mesh + optional sphereSweep-mesh collisions for each individual hair strand. How do you think this would be possible on a single cpu for hundreds of hair strands on hundreds of player meshes?
    And how does sending the information via the network change the frequency of physics updates? They are calculated and sent just as often as player transform updates. If the ping is low the physics updates are sent late, but they are sent at the same frequency, aren't they?
     
  11. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Unless you're making a hairdressing MMO, leave it out of the pipeline (network). Its not impossible, just difficult solely because of the non-deterministic behavior of physics in general.

    Cloth can be simulated on each client, if they have it on.. I would consider cloth/hair a high-end feature that might be disabled on lower end computers.
     
    Ony and Kiwasi like this.
  12. Deleted User

    Deleted User

    Guest

    It's not impossible, usually it is how it is because MMO's are lightweight and currently want as many players with crappy hardware as they possibly can.. It's a numbers game, if they made it look and interact like Crysis 3 they'd cut off a massive part of their clientele.

    All you're doing is replication of an "actor / pawn / skeletal mesh" for vector information, player statistics, what's visible etc. If you want the game to support advanced physics like hairworks, it's nothing more than what you put "into the game"..

    You don't replicate vector information for specific strands or anything silly like that..

    I think you need to look into how multiplayer and networking actually works.. P.S I know it's not for Unity, but it's pretty relevant:

    P.S Notice the cloth movement on the "actor"?

     
  13. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,148
    Why would you necessarily calculate the hair physics on a CPU? NVIDIA has a platform for hair simulation that runs off their graphical hardware. While I haven't looked into it in-depth I don't know why you wouldn't be able to make use of it.
     
  14. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    if a player hacks surely they'd hack something other than hair & clothing so would checking these things indicate that they've hacked elsewhere? or are hairdressers out to get you? :p
     
  15. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    I think you need to tell us exactly what you're thinking of simulating. Are you talking about every hair on someone's head, or..?

    Then consider required LOD. Having epic hair on characters near your screen could be awesome, but you don't need to support hundreds of characters for that - maybe a dozen? There's a 90% saving in require silicon force straight away. The rest can have a lower quality swishy hair model.

    Then think about the distribution of effort for the high quality hair rendering on the few nearby characters. Is it mostly CPU, or is it (or can it be) mostly GPU?

    Finally...
    ... will the positioning of strands of hair impact on a player's decision making, scene visibility, or otherwise effect the inputs they might give the game? If "no" then it doesn't effect gameplay, it's a purely visual effect.
     
    kiriri and Ryiah like this.
  16. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    maybe its a JPRG MMO? hair seems to be important in those
     
  17. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Back in my day jRPG's only had spiky hair and we liked it... Okay, we bitched about, but still it was good enough.
     
    Ony and calmcarrots like this.
  18. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    I'm sorry I didn't make that clear before. My physics are deterministic. It's a major requirement for my physics datatypes, because they do not store absolute information.

    I am working on a Virtual Reality (Occulus Rift) social MMO. It is not a JRPG but the graphics are definitely inspired by it. I have already created a hair creation tool for the artists so they can just draw in hair strands, make them spiky or not, make their base triangular or circular, things like that. This hair is updated based on a bezier curve every frame. So only the bezier curve needs to be simulated (think of the curve as the bone of the hair). Now since we already have this toolset, I thought it could be made available to all users ingame as well, because the actual data required to model these hair strands is very minimal. Remember the game Second Life? Remember how people went over character customization? These things are important to many people.

    Now I'll need to get to the character creation : Character creation in this game is blendshape driven. Eg a big person has a blendshape that makes it taller and then the character creator recalculates their rig to fit. This is made this way because big people are not just bigger versions of smaller people, but they actually have different proportions when it comes to arm/leg/torso length.
    So in the game you can expect every single player to have a unique hairstyle,character mesh and rig. We can't send baked data for each character and we can't really cache it without loads of RAM.

    You are right of course. I have not implemented an LOD system yet. It would make a major difference.

    I've tried my hardest to write linear code, so yes this is definitely possible and much much faster. Previously I couldn't use it because I didn't quite know what hardware the players would be using. Eg I can't develop for CUDA if some of my players use OpenCL and some others use something I've never heard of before. Now with the new work on ComputeShaders in Unity this is an option again.

    But even with the GPU acceleration this will still tax the users pc to the max if many different characters need to be calculated at once. All this calculation stalls the main cpu thread and slows down the framerate. If we used my proposed technique instead, we could have hair and cloth simulations that could even take the environment and other players into account, without costing other users any more performance or bandwith, since only the final bezier curves need to be sent to the other players.
    Is exactly the point I'm after now that I think about it. Even crappy PCs will have some 20kb/s download capabilities, but they may not have a top graphics card that could handle all the physics calculations itself.

    This would enable users to use their performance for more important things, like drawing all those vertices that must be on the screen when hundreds of fairly high quality characters have to be rendered. Or it would allow low end computers to still have high end physics they could never have in any other game.
    Downloading or uploading this data would be optional, just like it would be if it was entirely client side only. It would not "force some unimportant data down the users internet connection"

    So let me ask the fundamental questions here :

    Aren't high quality physics and the additional free cycles for graphics worth an optional constant 20 (or let's talk worst case, 50) kb/s download? Is this not something every mmo player can ensure? Why would you possibly want to recalculate the same physics over and over on each client if the results are all the same?
    If the download was optional, then why?
     
    Last edited: Jul 27, 2015
  19. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    This is completely the wrong mindset, particularly when building an MMO, in my opinion.
    You should be avoiding using bandwidth wherever possible in an MMO, not avoiding using the players CPU.
    The way hair moves would not ever need to be synchronised across clients, there's just no need for it. Calculate it client side. The same for cloth, unless it's required for user interaction, like walking across some sort of cloth walkway or something...

    Rather than thinking about it as "I have a server and x number of client PC's", think "I have x number of server to client connections", then you'll start to see why you want to use less bandwidth. *Big hint here, it's money.

    Also the thread title is rather misleading. This wouldn't be physics that is better than single player games, it would be, at best, equal to it.
     
  20. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    But the whole point is that I'm establishing peer to peer connections and only occasionally checking them via the server. It shouldn't be much more expensive. Or if I summarize everyone's opinion here, I don't even need to check because nobody would go through the effort of hacking the game just to have his hair behave non physicy. Or if I did I could just have the client randomly sending the information to the server, instead of sending it constantly. That would limit the server load as well.

    Why wouldn't it be better? It would get you the same results at reduced cpu/gpu cycles. It would get high end results on PCs that would not be able to calculate physics for that many characters at once.
     
  21. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    Well limiting the server load is definitely what i'd focus on. So P2P would technically avoid that, but then you how do you decide where the actual calculation happens? Does each player sim their own hair, and sync it with other people? What happens to mobs/npc's? Does the server handle that (increases bandwidth)?
    Not to mention that all of these things would increase the clients data usage, AND you then need to establish and maintain P2P connections alongside a server-client relationship for an unknown amount of clients in an area.
    It's a lot of effort and resources for something that literally no-one would notice (difference between client calculated and P2P synced data for hair or cloth is something no-one would be able to tell apart).

    Ok, I'll let you have that one, though I'd have said better performing, rather than better, as the actual physics in technical terms would be just the same.

    And is this all just to reduce the resource cost on the client side? Why not just have a hair detail setting so low end machines run a simplified model?

    If it was an ocean's waves and all the clients were ships, totally makes sense to use something similar to this (though tbh I'd still just make it server controlled). But hair and cloth? It doesn't make sense to require all clients to have to see the exact same thing at all times. They wouldn't know any better.

    I'm not saying don't do it, but it's not something I'd spend my time on when there are probably more important things to work on in an MMO.
     
  22. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    If something doesn't actually affect gameplay then there's no reason to synchronize it across clients.

    Talking about sending hair position data across the network is crazy, you might as while just stream the whole game at that point.
     
  23. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Why do I suddenly feel like I know nothing about deterministic physics? Last I checked, the whole point of hair and cloth physics is that they respond to movement, but the easiest way deterministic physics works is by taking interaction out of the equation. Unless what is actually being done is pre-computing a bunch of hair animations (which could just as easily be done locally or be shipped on the disk), this is pie-in-the-sky musings with the cart before the horse.