am I doing something wrong in my script?

Options
ta having log in my game this and the code I'm using how can I improve it ??

private void sendBallVelocity()
{
//Rigidbody component = base.gameObject.GetComponent<Rigidbody>();
if (gameController.myShootTurn && !GlobalGameManager30.goalHappened)
{
//if (gameObject.transform.position.x > 0.5f || gameObject.transform.position.x < -0.5f || gameObject.transform.position.y > 0.5f || gameObject.transform.position.y < -0.5f)
// {
Vector3 velocity = base.gameObject.GetComponent<Rigidbody>().velocity;
Vector3 velocityaangular = base.gameObject.GetComponent<Rigidbody>().angularVelocity;
Vector3 position = base.gameObject.GetComponent<Rigidbody>().position;
int ping = PhotonNetwork.GetPing();
object[] eventContent = new object[4]
{
velocityaangular,
velocity,
position,
ping
};
RaiseEventOptions raiseEventOptions = new RaiseEventOptions
{
Receivers = ReceiverGroup.Others
};

SendOptions sendOptions = default(SendOptions);
sendOptions.Reliability = true;
SendOptions sendOptions2 = sendOptions;
PhotonNetwork.RaiseEvent(fixBallCode, eventContent, raiseEventOptions, sendOptions2);

// }
}
}


public void OnEvent(EventData photonEvent)
{
if (photonEvent.Code == fixBallCode)
{
if (!gameController.myShootTurn && fixedCounter == 1)
{
object[] obj = (object[])photonEvent.CustomData;
Vector3 angular = (Vector3)obj[0];
Vector3 vector = (Vector3)obj[1];
Vector3 a = (Vector3)obj[2];
int num = (int)obj[3];
int num2 = (int)(PhotonNetwork.GetPing() / 2 + num / 2);
base.gameObject.GetComponent<Rigidbody>().angularVelocity = angular;
base.gameObject.GetComponent<Rigidbody>().velocity = vector;
base.gameObject.transform.position = a + vector * (num2 / 4000);
}
if (!gameController.myShootTurn)
{
fixedCounter++;
}
if (fixedCounter > 10)
{
fixedCounter = 0;
}
}
}

Comments

  • LeeroiJenkiins
    edited December 2020
    Options
    I'm sorry, what is your question here?
    What's not working properly and is there an Error message?

    You have a lot of random // in your code that may be generating some errors..? I see a missing '}' near the top there cause its commented out.

    You need to provide a better explanation as to what the outcome you want is, and what the current outcome is so I have a better idea of whats going wrong.


  • my synchronization is not good can you help me? is the same in this video what can be wrong ??

    https://youtu.be/jtyqqprkg48
  • LeeroiJenkiins
    edited December 2020
    Options
    By far the easiest fix I can see right now, although it could be many thing's is that you're velocity might not be sending properly, you may need to use your own IPunObservable to update it to each player with a custom stream. If you're Instantiating it and you want to smooth the lag abit, on your Photon View component of the ball, make sure its synchronization type is set to: Unreliable.

    Are the balls created through an RPC, instantiation or Room/Scene Instantiation?
    or is it an RPC called from an Instantiation?

    - If its an Instantiation, are you syncing the balls with Photon Rigidbody View or are you using your own IPunObservable to update it?
    - If its an RPC, are you making all the position change calls in the RPC?
    - also make sure its movement calls are done through a FixedUpdate or IEnumerator using yield return new WaitForFixedUpdate()

    If you're creating it through an RPC, how are you instantiating it? as a unity object, room object or Photon Instantiate?

    To me the correct logic to perform what you want is:
    - PhotonNetwork.Instantiate for your player
    - Each player then instantiates their own balls with photon instantiate, since they'll need to control it
    (Each of these balls would have their own PhotonView, Photon Animator View, Photon Rigidbody View)
    - Player sends an RPC call on said object to be moved
  • these are the ball and button scripts if you want to modify it to see if it improves. or if you want to connect here via remote assistance to see the problem it would be of great help.
    https://drive.google.com/file/d/1is6fV4kb623DnxGMaAgX1CxXHviS-rbj/view?usp=sharing
  • @claudiano2020 working on a project right now so won't have time to check it out till tomorrow morning, but i'll see if theres something I can do.
  • @LeeroiJenkiins right thank you very much
    i'm from brazil sorry my english.