Bullet wont collide for the other player (PHOTON+UNITY)

Options
Ive been working on a flamethrower as one of my weapons. Its a platform multiplayer online game. It is also working with photon. I am having a problem with the flames(and the other rifles bullets too). THe flames which the flamethrower shoots are being instantiated with PhotonNetwork.Instantiate... And they do collide with the player which instantiated them, and the other player is able to see them instantiated and their movement. But for some reason the player which instantiates them sees who they collide to and sees them collided but the other player which is shot at wont see the flames collided with himself or with the walls. The flames own their script of collision and movement and a photonView component.

What do I do to solve this issue?

Comments

  • Leepo
    Options
    What is the exact problem, please be more precise.


    I think the collision event is not fired for remote players(?).
    This is not per se a problem if you're fine with the owner of the 'bullet' sending the damage events. However thats not always desired. I think the collision events never occur because you are hard-setting the position of the rigidbody so that in the physisc world collision never happened. Check Rigidbody.moveto or something similar for alternative movement.


    Side note: How often are you instantiating and destroying photonviews when firing a gun? If this is 1 times per second or more you should redesign how you're firing your weapong: Have a photonview at the weapon and manage the firing from there...not via the bullets.
  • benk0913
    Options
    I have figured out that the collision happens between the character and the bullet only if the character moves while getting hit.
    It also happends when the character instantiates, If I wont move it at spawn it'll just fall down forever.
    By the way, I didnt use any rigidbodies for my player or my bullet.

    Theres the code targeted by the photonview component of the player:
    using UnityEngine;
    using System.Collections;

    public class nw_player : MonoBehaviour {

    public PhotonView playerPV;
    public Vector3 correctPlayerPos;
    public int animationInteger=0;
    public int animationRecieved=0;
    public int healthRecieved=100;
    public bool faceforRecieved=false;
    public bool ragdollRecieved;
    public bool ragdebugRecieved;
    public Vector3 directionRecieved;
    public string userRecieved;

    void Update()
    {
    if (!playerPV.isMine)
    {
    GetComponent<clientid2>().username=userRecieved;
    transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 20);
    GetComponent<player_movesys>().DisplayAnimation(animationRecieved);
    GetComponent<player_movesys>().facefor=faceforRecieved;
    GetComponent<player_movesys>().mousepos=directionRecieved;
    GetComponent<player_combat>().health=healthRecieved;
    GetComponent<player_ragdoll>().ragdoll=ragdollRecieved;
    GetComponent<player_ragdoll>().debugbool=ragdebugRecieved;
    GetComponent<clientid2>().username=userRecieved;

    if(faceforRecieved)
    {
    transform.rotation=Quaternion.Euler(0,-180,0);
    GetComponent<player_movesys>().chest.LookAt(directionRecieved,Vector3.left);
    }
    else
    {
    transform.rotation=Quaternion.Euler(0,0,0);
    GetComponent<player_movesys>().chest.LookAt(directionRecieved,Vector3.right);
    }
    }

    }


    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    if (stream.isWriting)
    {
    // We own this player: send the others our data
    stream.SendNext(transform.position);
    stream.SendNext(animationInteger);
    stream.SendNext (GetComponent<player_combat>().health);
    stream.SendNext (GetComponent<player_movesys>().facefor);
    stream.SendNext (GetComponent<player_ragdoll>().ragdoll);
    stream.SendNext (GetComponent<player_ragdoll>().debugbool);
    stream.SendNext (GetComponent<player_movesys>().mousepos);
    stream.SendNext (GetComponent<clientid2>().username);
    }
    else
    {
    // Network player, receive data
    this.correctPlayerPos = (Vector3)stream.ReceiveNext();
    this.animationRecieved=(int) stream.ReceiveNext();
    this.healthRecieved=(int) stream.ReceiveNext();
    this.faceforRecieved=(bool) stream.ReceiveNext();
    this.ragdollRecieved=(bool) stream.ReceiveNext();
    this.ragdebugRecieved=(bool) stream.ReceiveNext();
    this.directionRecieved=(Vector3) stream.ReceiveNext();
    this.userRecieved=(string) stream.ReceiveNext();

    }
    }
    }


    Heres the weapons code:
    using UnityEngine;
    using System.Collections;

    public class weapon_script_flame : MonoBehaviour
    {
    public GameObject playerHold;
    public float rateOfFire=5;
    private float rateOfFireActive;
    public float maxammo=200;
    public float ammo=200;
    public float magazines=0;
    public bool firetest=false;
    public GameObject bullet;
    public GameObject gunpoint;

    void Start()
    {
    rateOfFireActive=rateOfFire;
    }

    void Update ()
    {

    if(firetest)
    {
    Fire ();
    firetest=false;
    }

    }


    public void Reload()
    {
    if(magazines>0)
    {
    ammo=maxammo;
    magazines--;
    }
    }


    public void TriggerWeapon()
    {
    if(rateOfFireActive>0)
    {
    rateOfFireActive-=1*Time.deltaTime;
    }
    else
    {
    if(ammo>0)
    {
    rateOfFireActive=rateOfFire;
    Fire ();
    ammo-=1;
    }
    else
    {
    print ("out of ammo!");
    }
    }
    }

    void Fire()
    {
    GameObject tempflame;
    tempflame=PhotonNetwork.Instantiate ("Flame",gunpoint.transform.position,gunpoint.transform.rotation,0);
    tempflame.GetComponent<bullet_script>().enabled=true;
    tempflame.GetComponent<bullet_script>().playerOwn=playerHold;
    }
    }

    And the bullets code:
    using UnityEngine;
    using System.Collections;

    public class bullet_script : MonoBehaviour {

    public GameObject playerOwn;
    public float speed=50;
    public GameObject me;
    public float timed=5;
    public int dmgvalue=5;

    void Update()
    {
    transform.position+=transform.TransformDirection(0,1,0)*Time.deltaTime*speed;

    if(timed>0)
    {
    timed-=1*Time.deltaTime;
    }
    else
    {
    Destroy (me);
    }

    }

    void OnTriggerEnter(Collider victim)
    {
    print ("crap?");
    //if(victim.gameObject!=playerOwn)
    //{
    GameObject grave;
    if(victim.gameObject.tag=="Player")
    {
    print ("isplayer!");
    grave=(GameObject)Resources.Load("Collidedblood");
    victim.GetComponent<player_combat>().Wound(dmgvalue);

    }
    else if(victim.gameObject.tag=="Wood")
    {
    grave=(GameObject)Resources.Load("Collidedwood");
    }
    else
    grave=(GameObject)Resources.Load("Collidedust");


    Instantiate (grave,transform.position,transform.rotation);
    Destroy (me);
    //}

    }






    }

    Also the combat code(which handles the characters health):
    using UnityEngine;
    using System.Collections;

    public class player_combat : MonoBehaviour {

    public GameObject me;
    public int weaponid=0;
    public int health=100;
    public float woundtime=3;
    //gameobjects
    public GameObject nicktext;
    public GameObject nicktext2;
    public GameObject gunhold;
    public GameObject holdedWeapon;
    //Faces
    public GameObject faceside1;
    public GameObject faceside2;
    //BOOLS
    public bool update=false;
    public bool shootable=true;
    public bool isControllable=false;
    public bool faceinstalled=false;
    public bool facerecieved=false;
    //Face Textures
    public Texture f_default;
    public Texture f_wounded;
    public Texture f_spree;
    public Texture f_dead;


    void OnGUI()
    {
    GUI.Label(new Rect(0,0,150,50),"Health: "+health);

    }

    void Update ()
    {

    if(GetComponent<player_movesys>().facefor)
    {
    nicktext.GetComponent<TextMesh>().text="";
    nicktext2.GetComponent<TextMesh>().text=GetComponent<clientid2>().username;
    }
    else
    {
    nicktext2.GetComponent<TextMesh>().text="";
    nicktext.GetComponent<TextMesh>().text=GetComponent<clientid2>().username;
    }


    if(f_default!=null && !faceinstalled)
    {
    faceside1.renderer.material.mainTexture=f_default;
    faceside2.renderer.material.mainTexture=f_default;
    faceinstalled=true;
    }

    if(woundtime>0)
    {
    woundtime-=1*Time.deltaTime;
    if(faceside1.renderer.material.mainTexture!=f_wounded)
    {
    faceside1.renderer.material.mainTexture=f_wounded;
    faceside2.renderer.material.mainTexture=f_wounded;
    }
    }
    else
    faceinstalled=false;

    if(health<=0)
    Death();

    if(weaponid == 1)
    {
    if(isControllable)
    {
    if(Input.GetMouseButtonDown(0) && shootable)
    holdedWeapon.GetComponent<weapon_script_pistol>().TriggerWeapon();

    if(Input.GetKeyDown(KeyCode.R))
    {
    holdedWeapon.GetComponent<weapon_script_pistol>().Reload();
    }
    }
    }





    if(weaponid==2)
    {
    if(isControllable)
    {
    if(Input.GetMouseButton(0) && shootable)
    holdedWeapon.GetComponent<weapon_script_ar>().TriggerWeapon();

    if(Input.GetKeyDown(KeyCode.R))
    {
    holdedWeapon.GetComponent<weapon_script_ar>().Reload();
    }

    }
    }



    if(weaponid==4)
    {
    if(isControllable)
    {
    if(Input.GetMouseButton(0) && shootable)
    holdedWeapon.GetComponent<weapon_script_flame>().TriggerWeapon();

    if(Input.GetKeyDown(KeyCode.R))
    {
    holdedWeapon.GetComponent<weapon_script_flame>().Reload();
    }

    }
    }









    if(update)
    {
    UpdateGun ();
    update=false;
    }
    }

    void UpdateGun()
    {
    GameObject.Destroy(holdedWeapon);

    if(weaponid==1)
    {
    me.GetComponent<player_movesys>().rifle=false;
    me.GetComponent<player_movesys>().poseswitch();
    holdedWeapon=(GameObject)PhotonNetwork.Instantiate ( "weapons_e_pistol", gunhold.transform.position , gunhold.transform.rotation ,0);
    holdedWeapon.transform.parent=gunhold.transform;
    holdedWeapon.GetComponent<weapon_script_pistol>().playerHold=me;
    }

    if(weaponid==2)
    {
    me.GetComponent<player_movesys>().rifle=true;
    me.GetComponent<player_movesys>().poseswitch();
    holdedWeapon=(GameObject)PhotonNetwork.Instantiate ("weapons_e_assault1", gunhold.transform.position , gunhold.transform.rotation ,0);
    holdedWeapon.transform.parent=gunhold.transform;
    holdedWeapon.GetComponent<weapon_script_ar>().playerHold=me;
    }

    if(weaponid==4)
    {
    me.GetComponent<player_movesys>().rifle=true;
    me.GetComponent<player_movesys>().poseswitch();
    holdedWeapon=(GameObject)PhotonNetwork.Instantiate ("weapons_e_flamet", gunhold.transform.position , gunhold.transform.rotation ,0);
    holdedWeapon.transform.parent=gunhold.transform;
    holdedWeapon.GetComponent<weapon_script_flame>().playerHold=me;
    }
    }

    public void Death()
    {
    GetComponent<player_ragdoll>().ragdoll=true;
    GetComponent<player_ragdoll>().Turn();
    }

    public void Wound(int dmg)
    {
    woundtime=3;
    health-=dmg;

    }
    }


    By the way, to the side note- I dont know how correct it whould be if the bullets were client side.