Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - blueace

Pages: [1]
1
Network / UDP sends both players packets to one of them
« on: August 10, 2018, 09:53:54 pm »
When player gets ID-0 he always receives the position of himself and the other player which causes his position to flicker between his actual one and the other players each frame. I've been going through the code multiple times and can't understand why it's doing that.

Any help would be greatly appreciated.

CLIENT CODE - https://hastebin.com/kukiyabopu.php
SERVER CODE - https://hastebin.com/ceboyawobi.cpp

server -

                        if (socket.receive(player1Pac, clients[0].address, clients[0].port) == sf::Socket::Done)
                        {
                                sf::Vector2i pos;

                                //player1Pac >> pos.x >> pos.y;
                               
                                socket.send(player1Pac, clients[1].address, clients[1].port);
                                //cout << "Sent info to player 2" << endl;

                                player1Pac.clear();
                        }
                        // send player 2 data to player 1
                        if (socket.receive(player2Pac, clients[1].address, clients[1].port) == sf::Socket::Done)
                        {

                                sf::Vector2i pos2;

                                //player2Pac >> pos2.x >> pos2.y;

                                socket.send(player2Pac, clients[0].address, clients[0].port);
                                //cout << "Sent info to player 1" << endl;
                                player2Pac.clear();
                        }

client -

                if (myID == 1)
                {
                        //cout << "myID: " << myID << endl;
                        //cout << "player 2 pos:" << OtherX << ":" << OtherY << endl;
                        //system("cls");
                        Players[1].setPosition(Xposition, Yposition);
                        Players[0].setPosition(OtherX, OtherY);
                }
                else if (myID == 0)
                {
                        //cout << "myID: " << myID << endl;
                        //cout << "player 1 pos:" << OtherX << ":" << OtherY << endl;
                        //system("cls");
                        Players[0].setPosition(Xposition, Yposition);

                        Players[1].setPosition(OtherX, OtherY);
                }

Pages: [1]