XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

collision on gameplayer over network

Last post 09-23-2008 11:36 PM by Twanks. 3 replies.
  • 09-22-2008 7:41 PM

    collision on gameplayer over network

     

    hello

    i have run in to some problems

    i use the peer to peer sample

    i can do collision on the world

    but i can not do collision between game players

    i was thinking of this

    there are only 2 players in the game

    foreach (NetworkGamer gamer in networkSession.AllGamers)

    {

    if (gamer.IsHost)

    {

        get the bounding box

    }

    if (gamer.IsLocal)

    {

    get the bounding box

    }

    and compare those to bounding box

    but it doesent work

     

    any iders

    hope some can help

     

     

     

    Michael Hansen XNA Rocks..
  • 09-22-2008 10:45 PM In reply to

    Re: collision on gameplayer over network

    Define "get the bounding box" ?

    Define "compare those to bounding box" ?

    Define "but it doesent work" ?

    Your question is a little vague...

    XNA Framework Developer - blog - homepage
  • 09-23-2008 4:05 PM In reply to

    Re: collision on gameplayer over network

     

     

    here is the actuly code but i cant get to work the gameplayer is do collision on him self and not on the other game player

    i can draw bullets and animation on the game players

    do it have something that the there are other stuff shareing thes 3 Vector3 vlaues , but thay are not modefied only by local gamepad

    so bad luck for my dreambuildplay entry

    no collision on game players

     

    all tree Vector3 are shared over network, bullets alsol use GameplayerPos and the actuly move of players

    GamePlayerMin

    GmaeplayerMax

    GameplayerPos

     

    BoundingBox boxPlayer_1;

    BoundingBox boxPlayer_2;

    public void DrawNetworkPlayers(EvoFxCamera camera, EvoFxLight light, EvoFxTimer timer)

    {

    // For each person in the session...

    foreach (NetworkGamer gamer in networkSession.AllGamers)

    {

    BoundingBox boxPlayer_1;

    // Look up the tank object belonging to this network gamer.

    Players tank = gamer.Tag as Players;

            if (gamer.IsHost)

            {

                    boxPlayer_1 = new BoundingBox(tank.GamePlayerMin +tank.GamePlayerPos,boxPlayer_1.Max +tank.GamePlayerPos);

            }

            if (gamer.IsLocal)

            {

                    boxPlayer_2 = new BoundingBox(tank.GamePlayerMin +tank.GamePlayerPo s,  boxPlayer_1.Max +tank.GamePlayerPos);

            }

                        if (boxPlayer_1.Intersects(boxPlayer_2))

                        {

    // we have a collision

                        UpdateCollisionPlayer(tank.GamePlayerPos);

                        }

                    else

                        {

                                if (boxPlayer_2.Intersects(boxPlayer_3))

                                    {

                                        UpdateCollisionPlayer(tank.GamePlayerPos);

                                    }

                }

    }

    Michael Hansen XNA Rocks..
  • 09-23-2008 11:36 PM In reply to

    Re: collision on gameplayer over network

    Well you can do what I did with my networking code and make a List that stores all of the positions. My game is 2D but you should be able to apply the same principles. Something like:

     

    //Place at top of class  
    List<Vector3> playerPositions = new List<Vector3>();  
     
    //I assume you're using the default networking code in the peer-to-peer sample  
    void ReadIncomingPackets(LocalNetworkGamer gamer)  
    {  
       while (gamer.IsDataAvailable)  
       {  
          NetworkGamer sender;  
            
          gamer.ReceiveData(packetReader, out sender);  
        
          if (sender.IsLocal)  
              continue;  
     
          Tank remoteTank = sender.Tag as Tank;  
            
          remoteTank.Position = packetReader.ReadVector3();  
     
          playerPositions.Add(tank.Position);  
     
          if (playerPositions.Count > networkSession.AllGamers.Count)  
          {  
              for (int i = 0; i < playerPositions.Count; i++)  
              {  
                 playerPositions.RemoveAt(i);  
                 i--;  
              }  
          }  
            
          }  
        }  
     
     
    void UpdateLocalGamer(LocalNetworkGamer gamer)  
    {  
       Tank localTank = gamer.Tag as Tank;  
         
       ReadTankInputs(localTank, gamer.SignedInGamer.PlayerIndex);  
     
       localTank.Update();  
     
       packetWriter.Write(localTank.Position);  
     
       gamer.SendData(packetWriter, SendDataOptions.InOrder);  
     
       //Create bounding box for local player here..........  
       //Then run a for loop on the playerPosition list to cycle through the different  
       //positions  
     
     }
     
    That should give you a good idea on how to handle collisions in your current situation.
    http://xblcgreviews.com
Page 1 of 1 (4 items) Previous Next