Search Unity

Vehicle wheels not synchronized between server and clients

Discussion in 'Multiplayer' started by Aubrey-Falconer, Feb 26, 2008.

  1. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    438
    Hello everyone!

    I have a very simple networking problem, but nothing I try solves it.

    I am working on a networked multiplayer racing game, more information about which is available at:
    http://forum.unity3d.com/viewtopic.php?t=9489&start=15

    Everything is working perfectly, except for the network synchronization of vehicles.
    When I link the network instantiator to "spawn" the example network vehicle provided by Unity, the game works perfectly. When I link it to the custom "Mars Buggy", although it is configured identically to the example vehicle as far as I can tell, the game works perfectly from the server machine's point of view - but the server and client vehicle on the client's screen have no wheels and can't move :)

    I have tried everything I can think of, but to no avail. I packaged the car and the entire game's source files, in case there is some benevolent individual who would do me the favor of examining them...

    Game: http://fun.theati.net/games/data/25/fullscreen.htm
    Vehicle: http://fun.theati.net/games/data/25/misc/vehicle.zip
    Source: http://fun.theati.net/games/data/25/misc/marsexplorer.zip

    Thanks everyone!

    -Aubrey

    Edit: This seems to be more strange than it first appeared... If I use a MacBook Pro to host the server and join with an iMac before the map is selected, the game works perfectly with the mars buggy as the vehicle. If I do the exact same procedure on any of the other computers I have laying around, the aforementioned tires disappearing on client machine bug occurs... Does the online networked version of the game work for anyone else?
     
  2. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    438
    Hmm... Upon further testing, I have verified that no matter what, the game never works when clients join a running game after the map is selected. If 1 client joins before the server selects a map, they have a 50% chance of working perfectly or having their tires disappear. If two clients join, even stranger things happen...

    Another issue I am experiencing is that in working network games (where only 1 client joins prior to the server selecting a map), although the game's physics are almost correct, the server and client cars both experience random intermittent slowdowns lasting for 5 - 10 seconds. I have the computers networked directly to each other using wifi, so network latency shouldn't be an issue...

    I initially thought this would be easy to solve, but it just keeps getting more strange :(
     
  3. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    438
    YAAAY! I just solved it :)

    The first problem I had was that I had the vehicle's network view component linked directly to the vehicle's transform component, instead of the vehicle's networkrigidbody script. Why this caused the tires to disappear I have no idea, but I think it may just have been that the car was "jittering" too much for them to stay connected or something... It seems obvious what I did wrong now, but I sure hope this post can save some other noob the grief I experienced if they run into this problem.

    The second problem it turned out that I had was that all the networked vehicles velocities were inexplicably connected. The networked cars all moved slower as more cars were connected, and whenever one vehicle slid down a hill backwards all the other cars would drive backwards even if they were on level ground. Thinking that this must be related to my previous network view problem I tried everything I could think of to solve it, but then I finally realized that somehow the private motor_speed variable in my car script had been declared as static - and that all the car scripts were sharing the same variable.

    Anyway, I am delighted that it is finally working, and everyone is free to join me on mars for some networked racing!

    {Except that I have satellite internet with super high network latency - so we may have to wait till I am at a wifi hotspot in town...}

    -Aubrey
     
  4. captnemo

    captnemo

    Joined:
    Mar 21, 2008
    Posts:
    9
    That mars racer is cool!!! nice work bud

    Thanks for download also I need to learn from you, I want to do something like this with a little more of a rally car feel to it on dirt, like when you powerslide in the wet
     
  5. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    438
    You should be able to get a more "powerslide" feel by adjusting the friction settings on the vehicle's tire objects, and the surface settings of the terrain you will be working with.

    Thank Yoggy for the car! The Mars Vehicle is just a heavily modified version of his buggy :)