How To Access Rigidbody on Client Side using Netcode

Video showing the host and client side perspectives

I am using rigidbodies on the balls, which are not instantiated, and they are picked up via script¹, the host can access everything, but the client cannot access the rigidbodies, but supposedly can access the script (video explains the process). I am relatively new to Netcode, so if it’s something obvious, talk to me as if I am a 2 year old, and, preferably, point me in the right direction, or unity doc.


I’ve tried adding the Network Rigidbody with Network Transform (All of my objects (players and balls) have the Network Object component attached to them), which didn’t work. I have tried using my PlayerNetwork script, which makes the actual players move, but my players don’t use rigidbodies and the balls do, so it didn’t really help. I have tried my hand at RPC’s, but really dont understand it. If that’s what I need to use, then I’ll gladly read through the doc on it, but if I can avoid it, that would be great too.

Thanks in advance.


¹

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetBall : MonoBehaviour
{
    [SerializeField] private Camera cam;
    [SerializeField] private float distanceGrab;
    [SerializeField] private Transform ballHold;
    [SerializeField] private Transform ballThrow;
    [SerializeField] private GameObject ballGet;
    [SerializeField] private GameObject _ball;
    [SerializeField] private bool isHoldingBall;
    [SerializeField] private float charge;
    [SerializeField] private Rigidbody rb;
    [SerializeField] private RectTransform slider;
    [SerializeField] private GameObject pickUpDot;
    [SerializeField] private GameObject reticle;

    void Update()
    {
        if(_ball != null)
        {
            _ball.transform.position = ballHold.position;
            _ball.transform.rotation = new Quaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
        }
        if(isHoldingBall == false)
        {
            GrabBall();
        }
        if(isHoldingBall == true)
        {
            ThrowBall();
        }
    }

    void OnTriggerEnter(Collider ball)
    {
        
    }

    void GrabBall()
    {
        ballGet.SetActive(true);
        reticle.SetActive(false);

        if(ballGet.transform.GetComponent<BallInSphere>().canPickUp == true)
        {
            pickUpDot.SetActive(true);
            if(Input.GetButtonDown("Fire1"))
            {
                _ball = ballGet.transform.GetComponent<BallInSphere>().theBall;
                rb = _ball.GetComponent<Rigidbody>();
                rb.useGravity = false;
                rb.isKinematic = true;
            }
        }
        else if(ballGet.transform.GetComponent<BallInSphere>().canPickUp == false)
        {
            pickUpDot.SetActive(false);
        }

        if(_ball != null)
        {
            isHoldingBall = true;
        }
    }

    void ThrowBall()
    {
        ballGet.SetActive(false);
        pickUpDot.SetActive(false);
        reticle.SetActive(true);
        slider.sizeDelta = new Vector2(slider.transform.localScale.x * charge * 100f, 100f);
        if(_ball != null)
        {
            if(Input.GetButton("Fire2"))
            {
                charge += 20f * Time.deltaTime;
                if(charge >=10)
                {
                    charge = 10;
                }
            }

            if(!Input.GetButton("Fire2"))
            {
                charge -= 20f * Time.deltaTime;
                if(charge <= 0)
                {
                    charge = 0;
                }
            }

            if(Input.GetButtonDown("Fire1") && charge > 0)
            {
                _ball.transform.GetComponent<I_Am_Ball>().canHit = true;
                _ball.transform.position = ballThrow.position;
                rb = _ball.GetComponent<Rigidbody>();
                rb.useGravity = true;
                rb.isKinematic = false;
                rb.AddForce(cam.transform.forward * charge * 300);
                isHoldingBall = false;
                _ball = null;
                rb = null;
                charge = 0f;
                slider.sizeDelta = new Vector2(0f, 100f);
            }
        }
    }
}

Did you ever figure out a fix for your problem? @TsunamaCade