need help with camera shake photon unity

i use unity’s FPS controller.i manage to make camera shake on the other players.

the idea is. i shoot, my camera shakes. and when enemy is hit, his camera shakes as well. like feeling the impact.

so i manage to do this. i use allbuffered. but the problem is, everyone who are not hit are affected as well. i was confused. i manage to do this with damage health script without any problem. (only the target is affected).
but with the camera shake. it affects everyone. did i miss something or is it something with photonnetwork target?

i use raycast. and store all my hit components. and able to read parent or child.

i will show you the script. it may be dirty. was really want to manage how to fix this issue. i have the clean version one before i try to do camera shake on enemies cam.

my goal for this is, i only want the enemie’s cam to shake(who is hit by my raycast) would be the only one affect. not everyone else or yourself.

    public float firerate = 0.1f;
    public float cooldown = 0;
    public float damage = 25f;
    public float impactforce = 50f;
    public float forcemultiplier = 1;

    public bool focus = false;
    float offsetvalue;
    void Update()
    {

        cooldown -= Time.deltaTime;

        if (Input.GetButton("Fire1"))
        {
            Fire();



        }

        if (Input.GetButtonDown("Fire2"))
        {
            focus = !focus;

        }

    }

    void Fire()
    {
        if (focus)
        {
            offsetvalue = 0.02f;
        }
        else { offsetvalue = 0.05f; }
        Vector3 offset = new Vector3(Random.Range(-offsetvalue, offsetvalue), Random.Range(-offsetvalue, offsetvalue), 0);

        if (cooldown > 0) return;


        Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward + offset);






        Transform hitTransform;    //name of object you hit

        Vector3 hitPoints;    //location of object hit


        hitTransform = FindCloseshit(ray, out hitPoints);



        if (hitTransform != null)
        {


            Health h = hitTransform.GetComponent<Health>();   //Health is the script name

            while (h == null && hitTransform.parent)
            {

                //use in case if object is in a parent and has the health and collider

                hitTransform = hitTransform.parent;

                h = hitTransform.GetComponent<Health>();


            }

            if (h != null)
            {

                //  h.TakeDamage(damage);
                PhotonView pv = h.GetComponent<PhotonView>();


                if (pv == null)
                {
                    Debug.LogError("no photonview detected");
                }


                else
                {
                    h.GetComponent<PhotonView>().RPC("TakeDamage", PhotonTargets.AllBuffered, damage);


                }
            }

            if (hitTransform.childCount > 0)
            {

                var childobject = hitTransform.GetChild(0).GetChild(0);
                PhotonView pv = childobject.GetComponent<PhotonView>();
                camerashake CS = childobject.GetComponent<camerashake>();

       

                if (pv == null)
                {
                    Debug.LogError("no photonview detected");

                }
                else
                {
                  
                    CS.GetComponent<PhotonView>().RPC("cameraShake", PhotonTargets.AllBuffered);
           
                }
            }

        }

        cooldown = firerate;
    }








    Transform FindCloseshit(Ray ray, out Vector3 hitPoint)
    {

        RaycastHit[] hits = Physics.RaycastAll(ray);

        Transform closesHit = null;

        float distance = 0;
        float maxdistance = 2f;


        hitPoint = Vector3.zero;




        foreach (RaycastHit hit in hits)
        {
            Debug.DrawRay(hit.point, hitPoint);

            if (hit.transform != this.transform && (closesHit == null || hit.distance < distance))   //remove maxdistance if its long range
                                                                                                     //&& hit.distance < maxdistance
            {
                // we haved hit something that is:
                // 1.) not us
                // 2.) the first thing we hit(that is not us)
                // 3.)  or, if not b, is at least closer than the previous closest hit





                closesHit = hit.transform;

                distance = hit.distance;
                hitPoint = hit.point;


                Rigidbody pushforce = closesHit.GetComponent<Rigidbody>();
                if (pushforce != null)
                {

                    pushforce.AddForce(-hit.normal * (impactforce * forcemultiplier));
                }


            }

        }


        return closesHit;
    }

code for camerashake

   public static camerashake instance;

   
    Vector3 OrigCampos;

    Quaternion OrigCamRo;

    Quaternion randomrotate;

    public float amplitude = 0.03f;

    public float grenadeamp = 0.30f;

    public bool connected = false;


    public float countdown = 10;

    public float calculatedcountdown;


    public float shakeamount =0;

    public bool hitgrenade;










    void Start()
    {
        OrigCamRo.z = Camera.main.transform.localRotation.z;

        OrigCampos = Camera.main.transform.localPosition;

        hitgrenade = false;

          instance = this;

    }

    // Update is called once per frame
    void Update()
    {
       //OrigCamRo.y = Camera.main.transform.localRotation.y;

     //  OrigCamRo.x = Camera.main.transform.localRotation.x;

        countdown -= Time.deltaTime;

        grenadeshake();






            if (Input.GetKey("m"))
            {


            Debug.Log("localrotation x is "+Camera.main.transform.localRotation.x);
            Debug.Log("origcamro.x is " + OrigCamRo.x);

            Debug.Log("overall local rotations " + Camera.main.transform.localRotation);

        }




    }




    /// <summary>
    /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// </summary>

    [PunRPC]
    public void cameraShake()
    {  
        Camera.main.transform.localPosition = Camera.main.transform.localPosition + Random.insideUnitSphere * amplitude;

    }












    /// <summary>
    /// //////////////////////////////////////////////////////////////////////////////////////////
    /// </summary>

    public void restorePos()

    {
        Debug.Log("camera in  work");

        Camera.main.transform.localPosition = Vector3.Lerp(Camera.main.transform.localPosition, OrigCampos, 1f * Time.deltaTime);

        if (Camera.main.transform.localPosition == OrigCampos)
        {
            Debug.Log("camera in localposition!");
        }
    }
    


           [PunRPC]
    public void grenadehit(float calculatedcountdown)
    {
     
        Debug.Log("RPC WORKS");
        countdown = calculatedcountdown;
      
    }




      

    void grenadeshake()

    {

        if (countdown > 0)
       {



          Camera.main.transform.localRotation = Camera.main.transform.localRotation * Quaternion.Euler(0, 0, Random.Range(-100f, 100f));
             }

           else if (countdown <= 0)
            {


       

           Camera.main.transform.localRotation = Quaternion.Lerp( Camera.main.transform.localRotation, Quaternion.Euler(Camera.main.transform.localRotation.x, Camera.main.transform.localRotation.y, OrigCamRo.z), 1f * Time.deltaTime);


        }

    }

Hi,

I guess it is easier to move the discussion to the official forum where you also made this topic. So for anyone who is interest in this, please follow the discussion here.

  public float firerate = 0.1f;
    public float cooldown = 0;
    public float damage = 3f;
    public float impactforce = 50f;
    public float forcemultiplier = 1;

    public bool focus = false;
    float recoilvalue;

    public float maxrecoilfocus;
    public float maxrecoilnotfocus;
    float offsetvalue;

    public static playershoot instance;
    Animator animation;

    void Start()
    {
        PhotonView photonView = this.photonView;

        animation = GetComponent<Animator>();

 

        instance = this;

        recoilvalue = 0;


        if (!photonView.isMine)

        {


            GetComponent<playershoot>().enabled = false;


        }



    }




    void Update()
    {
       

        cooldown -= Time.deltaTime;

        if (Input.GetButton("Fire1"))
        {
            Fire();
       

            camerashake.instance.cameraShake();

        }

        else
        {
            camerashake.instance.restorePos();

            recoilvalue = 0;
        }

        if (Input.GetButtonDown("Fire2"))
        {
            focus = !focus;

        }

        if (Input.GetKey(KeyCode.LeftShift))
        {
            focus = false;

        }






    }





    void Fire()
    {


        if (focus)
        {

            recoilvalue += Mathf.Lerp(0f, maxrecoilfocus, 1f * Time.deltaTime);

            if (recoilvalue >= maxrecoilfocus)
            {
                recoilvalue = maxrecoilfocus;
            }
            offsetvalue = 0.02f;
        }

        else { offsetvalue = 0.05f;


            recoilvalue += Mathf.Lerp(0f, maxrecoilnotfocus, 1f * Time.deltaTime);
        }



      

        if (recoilvalue >= maxrecoilnotfocus)
        {
            recoilvalue = maxrecoilnotfocus;
        }



        Vector3 recoil = new Vector3(0, recoilvalue, 0);


        Vector3 offset = new Vector3(Random.Range(-offsetvalue, offsetvalue), Random.Range(-offsetvalue, offsetvalue), 0);




        if (cooldown > 0) return;


        animation.SetTrigger("shoot");

        Ray ray = new Ray(Camera.main.transform.position, (Camera.main.transform.forward) + offset + recoil);

        Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward);




        Transform hitTransform;    //name of object you hit

        Vector3 hitPoints;    //location of object hit


        hitTransform = FindCloseshit(ray, out hitPoints);



        if (hitTransform != null)
        {


         

            Health h = hitTransform.GetComponent<Health>();   //Health is the script name

            if (hitTransform.childCount > 0)

            {

                var childobject = hitTransform.GetChild(0);

                if (!childobject) return;

             
                camerashake CS = childobject.GetComponent<camerashake>();
     

            

                if (CS != null)


                {
                    PhotonView pv2 = CS.GetComponent<PhotonView>();

                    if (pv2 == null)
                   {
                       Debug.LogError("no photonview detected");
                   }


                   else
                   {
                       CS.GetComponent<PhotonView>().RPC("cameraShake", PhotonTargets.AllBuffered);

                       Debug.Log("working!!!!");
                   }

                }

            }
               
      

                



          

            while (h == null && hitTransform.parent )
            {

                //use in case if object is in a parent and has the health and collider

                hitTransform = hitTransform.parent;

                h = hitTransform.GetComponent<Health>();

               


            }

            if (h != null)
            {

                //  h.TakeDamage(damage);
                PhotonView pv = h.GetComponent<PhotonView>();


                if (pv == null)
                {
                    Debug.LogError("no photonview detected");
                }


                else
                {
                    h.GetComponent<PhotonView>().RPC("TakeDamage", PhotonTargets.AllBuffered, damage);

                }
            }


          

        }

        cooldown = firerate;
    }








    Transform FindCloseshit(Ray ray, out Vector3 hitPoint)
    {

        RaycastHit[] hits = Physics.RaycastAll(ray);

        Transform closesHit = null;

        float distance = 0;
        // float maxdistance = 2f;


        hitPoint = Vector3.zero;




        foreach (RaycastHit hit in hits) // for every hit inside the raycast array
        {
 

            //thie transform does not equal to this character
            if (hit.transform != this.transform.parent.parent.parent && (closesHit == null || hit.distance < distance))   //remove maxdistance if its long range
                                                                                                     //&& hit.distance < maxdistance
            {   
                // we haved hit something that is:
                // 1.) not us
                // 2.) the first thing we hit(that is not us)
                // 3.)  or, if not b, is at least closer than the previous closest hit





                closesHit = hit.transform;

                distance = hit.distance;
                hitPoint = hit.point;

                PhotonView pv = closesHit.GetComponent<PhotonView>();

                Rigidbody pushforce = closesHit.GetComponent<Rigidbody>();
                if (pushforce != null && pv != null)
                {

                    pushforce.AddForce(-hit.normal * (impactforce * forcemultiplier));

                }


            }

        }


        return closesHit;
    }