Sending RPC with Input

Options
Hi all,

I have a question regarding the Unity Input engine and Photon. I have the following code:

On my player, I have the following code:

if (Input.GetButtonDown("Fire1"))
{ 
    HitBall(transform.position, collisionRadius);
}

void HitBall(Vector3 center, float radius)
{
    hitCollider = Physics.OverlapSphere(center, radius);
    foreach (Collider collider in hitCollider)
    {
        if (collider.CompareTag("Ball"))
        {
            if (PhotonNetwork.IsConnected)
            {
               collider.GetComponent<PhotonView>().RPC("RPC_HitBall", RpcTarget.All, GetComponentInChildren<Camera>().transform.forward);
            }
        }
    }
}


Then, on my ball object, I have the following

[PunRPC]
public void RPC_HitBall(Vector3 direction)
{
    Vector3 pushDir = direction;
    GetComponent<Rigidbody>().velocity = Vector3.zero;
    GetComponent<Rigidbody>().velocity = (pushDir * 75.0f) + new Vector3(0, 10, 0);
}


This works great for both the host and client, the only issue is, there's a slight delay from the client side, so when the client presses "Fire1", the RPC call doesn't happen until a few milliseconds later, but on the host side, it happens instantly.

Both objects have Photon Views, my player has a Photon Transform View and the ball has a Photon Rigidbody View. Is there are way I can reduce the time it takes for this call to be made client side?

Thanks in advance.

Cheers
Jason

Comments

  • JayFitz91
    Options
    I've temporarily fixed this by changing ownership of the ball to the client just before they hit the button, this removes any of the lag that was there before, but I'm not sure if changing ownership so often in a scene is a good idea.

    This is only a two person game so this seems to do the job as a workaround, still open to any other suggestions though