Search Unity

Odd Movment Affect

Discussion in 'Scripting' started by sherlockturtle, Nov 26, 2012.

  1. sherlockturtle

    sherlockturtle

    Joined:
    Jan 23, 2012
    Posts:
    592
    So whenever I use this script on my multyplayer game it seams when someone moves it moves the other players too. Any ideas how to fix? I tried it useing the "player" var and without it. Player is themself.
    Code (csharp):
    1.  
    2. var projectile: Transform;
    3.  
    4. var gun : Transform;
    5.  
    6. var player : Transform;
    7.  
    8.  
    9.  
    10. function Start () {
    11.  
    12.  
    13.  
    14. }
    15.  
    16.  
    17.  
    18. function Update () {
    19.  
    20.  
    21.  
    22.  if (Input.GetKey(KeyCode.W)){
    23.  
    24.     player.Translate(Vector3.forward * Time.deltaTime * 2);
    25.  
    26.         }
    27.  
    28.         if (Input.GetKey (KeyCode.A)){
    29.  
    30.  player.Translate(Vector3.left * Time.deltaTime * 2);
    31.  
    32.         }
    33.  
    34.         if (Input.GetKey (KeyCode.S)){
    35.  
    36.     player.Translate(Vector3.back * Time.deltaTime * 2);
    37.  
    38.         }
    39.  
    40.         if (Input.GetKey (KeyCode.D)){
    41.  
    42.  player.Translate(Vector3.right* Time.deltaTime * 2);
    43.  
    44.         }
    45.  
    46.        
    47.  
    48.        
    49.  
    50.    
    51.  
    52.     }
    53.  
    54. }
    55.  
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Is that attached to all Player objects?

    If so, each one is polling for key presses and applying movement. You need this to be attached to *only* the GameObject you want to have listening for movement on the local machine.
     
  3. sherlockturtle

    sherlockturtle

    Joined:
    Jan 23, 2012
    Posts:
    592
    The game object is instated. How could I make it unique for that player?
     
  4. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    423
    Pull whole code in condition:

    Code (csharp):
    1. if(networkView.isMine) {
    2.  
    3. }
     
  5. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    423
    By the way, code is terrible. Use axis inputs like in default character controller script.
     
  6. sherlockturtle

    sherlockturtle

    Joined:
    Jan 23, 2012
    Posts:
    592
    ohh thanks. I got it working and it works realy smoothly now, but you control the other person instead of yourself, any ideas? I want you just to be abel to control your own character, not the other if you get what I mean.(Im useing 2 different computers for testing)
     
    Last edited: Nov 28, 2012
  7. sherlockturtle

    sherlockturtle

    Joined:
    Jan 23, 2012
    Posts:
    592
    Any ideas? Like I said now you just control the other player.. not yourself.