[HELP] It's soooo laggy (2D game)

Options
Hi,
I'm new PUN user, my (big) problem is so laggy, I used the Lerp trick (in NetworkCharacter script), but it's still bad , and as there is a lot of colliding between players in my game it's really not good.
Here is a resume of my situation so if you can help me:
671798PUN.jpg

and here is the NetworkCharacter script:
using UnityEngine;

public class NetworkCharacter : Photon.MonoBehaviour
{
    private Vector3 correctPlayerPos = Vector3.zero; 

    void Update()
    {
        if (!photonView.isMine)
        {
            transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, 0.5f);
        }
    }

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            // We own this player: send the others our data
            stream.SendNext(transform.position);
        }
        else
        {
            // Network player, receive data
            this.correctPlayerPos = (Vector3)stream.ReceiveNext();
        }
    }
}

Even all this , the movement of the opponent is laggy, and the ball too (for the Player2 , because the ball is instantiated in the Player1 device)

Comments

  • N1warhead
    Options
    Check out the Marco Polo tutorial. Heck it even has the script made on there, just copy paste it and your player will be smoothed out, at least within very reasonable smoothing as it takes time for packets to get sent and received, so it tries to predict where the player will be and lerp it..

    If I'm wrong I'm sure Tobias will be here to answer and correct me LOL.
  • vadim
    Options
    Hi,

    Lerp to last received position (as in code snipped above) can only make thing more laggy since it delays setting proper position for sake of smoothing. For latency compensation, prediction required as you mentioned.
    But I don't see any prediction in Marco Polo tutorial. Better check DemoSynchronization for that.
  • Thank you guys,
    as my game is full of movement (of the players) and collisions between players and the ball , I think it's so haard !
    is there a way to make the packets sending faster ?
  • I'm still waiting for help
  • N1warhead
    Options
    I'm not sure if you can do that, I would believe that would be based off your ISP (Internet Service Provider) depending on the connection speed to send and receive signals.
    However that may or may not be correct.

    But, it would be like instead of sending (random number - 20) packets a second, well if you wanted to send 100 packets a second there is virtually no point because it would take longer to receive a packet than to send 100 packets.

    How fast is your Internet speed? You can goto google and type in "Internet Speed Test" and should be one of the first ones, I believe it's called Speedtest.net..
    Run a test there and let us know how fast your Internet is.

    If your games going to be dealing with hardcore networking (lots of things going on) I'd recommend at least a 50 meg Internet connection to keep the Latency down,
    but preferably the 100 meg is more suitable.

    But that's neither true or false ^^^ above. It's just personal preference. But it is obviously faster to have a faster internet speed.

    if you're using PHYSICS (DON'T DO THAT) unless things have changed???? (Vadim???)
    As it is hard to use Physics over a network, it's doable, but at a cost of a lot more work for the predictions side of things,
    which with that, I could not help you with.
    If you are using Physics, you're better off faking Physics to push and roll your ball. Still a bit of work, but makes it easier for the Network to distinguish.
  • Thank you for the reply,
    here is my result:
    3907633358.png

    I'm playing 3D FPS games online without problem , so I don't think the internet speed is the problem here.
    and even if I have 100 meg as you say , the majority of the users will not have it.
  • N1warhead
    Options
    That there is your problem.

    As you can see, it says you're slower than 60% of whatever MA is.

    3.96 Mb/s a second is tremendously slow.

    Yeah most won't have a 100 Megs a second, but the majority do have at least a 20 meg a second connection.
    In today's standards 3.96 Mb/s is like a 56.K back in the day LOL. (Not literally) just a figure of speech.

    I highly recommend you upgrade your internet to at least a 20 meg or even a 10 meg will make a world of difference.

    When I was on 20 megs I was getting latency around 55 to 60 playing games.
    When it comes to gaming, ping is your best friend or worst enemy.
    When it comes to games, the download rate and upload rate are irrelevant, the ping is the most important part.
    I mean obviously a download rate and upload rate matter, as it helps with the Ping I would assume.

    But 133 Ping is kind of high, (technically).
  • vadim
    Options
    It depends on game traffic and 3.96 mb may be enough. But you need that bandwidth in both directions. 0.2 mb upload looks like real bottleneck.
    Anyway you should develop with good internet connection and after everything is ok, optimize app for more harsh conditions if required.
  • for the ping it was high only that night
    here is a new test
    3909529789.png

    But as I have already said, I play games like Ghost Recon Phantoms (high quality graphics and many players/action) and it works without any problem, so how can my 2D game be a problem for the internet speed ?
  • Games like Ghost Recon, COD, BF, etc all use the script that n1warhead mentioned (their own versions of course).


    Your Speed Test is pretty slow.

    Let me put it into perspective for you.

    When you're connected to a server, and sending data etc... (This goes for viewing web pages as well)

    You're downloading. Server is uploading.

    When you're uploading, server is downloading.

    So, think of it this way when you play a game like COD/BF/Ghost Recon...

    You're uploading "My Position", "My hit(When you shoot someone)", "When I get hit". To be fair, it's not a whole lot of info if highly optimized. Your .23 Mb/s might be fine...
    However, on the other players screen, you're all sorts of laggy.
    Your 4.07Mb/s download speed is good enough to actually see the other players just fine.


    You need to lerp the oldest received transform, with the new one. The script in the marco polo tutorial has it that you can literally drag/drop onto your project.

    The only way around this is: Increase your transmission rate of messages...a lot. Which, your internet can NOT handle.
  • N1warhead
    Options
    Cynikal nailed it on the head.

    ++++

    Games like BF, Ghost Recond, Etc. Have very very polished ends to their games.
    That's the difference between EA GAmes and us. They have teams of what, 30+ people? Who know exactly how to do their jobs and do it.

    Well, I can assume 95% of Indie developers who start messing with Networking still have a lot to learn. But that's just pure assumptions.
    But likewise, you can't expect a 15 line code to be as accurate as a as Ghost Recond which I can very well assume is probably hundreds if not thousands of lines just to get things extremely polished. (Again - my own assumption).

    So either upgrade your Internet speed or really really really learn how to polish out the jagged edges in your code and at least try an make it as smooth as you can.
  • vadim
    Options
    We don't know exactly what is the problem. One of assumption is bandwidth since you wrote that "my game is full of movement (of the players) and collisions between players and the ball". What is the traffic per sec. in you game?
    Btw, do DemoSynchronization demos work for you as or they are laggy too?
  • Yes , I tried the demo, the lerp method is good , but the others are laggy