Search Unity

[SOLVED] FPS multiplayer shoot issue

Discussion in 'Multiplayer' started by Faltren, Apr 10, 2017.

  1. Faltren

    Faltren

    Joined:
    Jan 10, 2017
    Posts:
    17
    Hello,
    I created a FPS which works fine in single player. However since I made it in multiplayer, the shoot doesn't work. In single Player, I made this :
    Code (CSharp):
    1.   private void Fire()
    2.     {
    3.         fireRate = 0.36f;
    4.  
    5.         nextFire = Time.time + fireRate;
    6.  
    7.         Rigidbody balle;
    8.  
    9.         i++;
    10.  
    11.         Quaternion qua = new Quaternion(0, 0, 0, 0);
    12.  
    13.         balle = Instantiate(balleCasting, transform.position, qua);
    14.         balle.velocity = transform.TransformDirection(Vector3.right) * ejectSpeed;
    15.         balle.isKinematic = false;
    16.  
    17.         balle.transform.rotation = new Quaternion(0, 0, 0, 0);
    18.  
    19.         balle.name = "Bullet " + I;
    20.  
    21.         shoot.Play();
    22.     }
    balle is the new bullet (which will be instantiate).
    ballecasting is the bullet which is in my gun.
    This script was placed on my gun (which is in my character).

    Now, because I'm in multiplayer, I can't use this script because I can't know if it is the local Player who is shooting or if it is another player (because the networkIdentity is placed on the root of my character and not on my gun). So I placed this script in the player's root (in order to be able to check the networkIdentity), this is the script :
    Code (CSharp):
    1. private void Fire()
    2.     {
    3.         fireRate = 0.36f;
    4.  
    5.         nextFire = Time.time + fireRate;
    6.  
    7.         Rigidbody balle;
    8.  
    9.         i++;
    10.  
    11.         balle = Instantiate(balleCasting, BulletPos.transform.position, Quaternion.identity);
    12.         balle.velocity = transform.TransformDirection(Vector3.forward) * ejectSpeed;
    13.         balle.isKinematic = false;
    14.  
    15.         balle.name = "Bullet " + i;
    16.  
    17.         shoot.Play();
    18.     }
    BulletPos is a gameObject which represent the position of the gun (and BalleCasting is the same thing as the first script).

    Finally this script DOESN'T work well : my bullet is shot but it just go in front of my character. So if I look in the sky, my bullet doesn't go in the sky, it only goes straight forwards.

    Can someone help me please 0_0.
     
  2. Faltren

    Faltren

    Joined:
    Jan 10, 2017
    Posts:
    17
unityunity