start position, if two the same, one loses out

Options
Kekora
Kekora
so I have this issue where if a player is instantiated at the same place as another player (the start position) then one of them goes up in the air a meter or two and flickers up and down (even though positional data is coming in saying they are on the ground) it shows them in the air and flickering up and down.

the result is that they keep moving up and down even after the other player has moved out of the way.

this doesn't happen during normal operation if one player moves out of the way before the second player comes in.

some more info about the player setup:
both players have rigidbody and capsule collider (rigidbody collision detection is set to "Continuous Dynamic"). gravity is only turned on for the local player, because dont want it conflicting with remote players positional updates.

Comments

  • Hi Kekora,

    this isn't an issue itself it is more or less a 'normal' behaviour. You are spawning a player inside another, which is handled by Unity's physics system by 'setting' one player up in the air. However:

    the result is that they keep moving up and down even after the other player has moved out of the way.


    this shouldn't happen. If one client had moved out of the way and they don't intersect any longer Unity's physics system shouldn't have any trouble with that situation. Do you use the PhotonView component to observe the objects' transform or do you use some custom logic in OnPhotonSerializeView(...) function? In the second case, setting the transform.position property might cause some trouble when having a Rigidbody attached to the game object. Therefore try using MovePosition(...) function on the Rigidbody component.
  • Kekora
    Kekora
    edited November 2016
    Options
    thanks.
    yes I have custom logic in a NetworkPlayer script which is watched by PhotonView.

    I tried to replace this..
    myDood.transform.position = Vector3.Lerp(myDood.transform.position, position, Time.deltaTime * lerpSmoothing);

    with this..
    myDood.GetComponent<Rigidbody>().MovePosition(Vector3.Lerp(myDood.transform.position, position, Time.deltaTime * lerpSmoothing));

    still the same jittering up and down during and after the spawning intersection.

    By design.. Gravity is on for the local player, and Gravity is off for the remote player.

    In Unity during runtime.. If I turn Gravity on for a few seconds on the remote player the jittering stops and he falls to the ground. But I can't use Gravity for remote players because it conflicts with network messages and messes up jumps etc.
    Also in Unity during runtime, if I turn on Freeze Position Y, the jittering stops, but again - I can't use that all the time because it stops all their up/down animations from working properly :) any other ideas?
  • Kekora
    Options
    I'm still looking for a solution to stop up/down jittering when two players are occupying the same space.

    As a test: I scripted a gravity function for remote players only that operates when their Animator is in Grounded state.
    A good idea but it ruins the positional updates when they are flying through the air (they ride lower than expected, even though at that time gravity is disabled).
  • jeanfabre
    Options
    Hi,

    -- one solution is to turn colliders into triggers at start, then you can figure out interestion and move users gracefully before turning colliders back to collision mode.

    Bye,

    Jean
  • Kekora
    Kekora
    edited November 2016
    Options
    thanks, that is a good idea.

    Edit: adding a bit of random start position in the X and Z so when the triggers and gravity come on, they are not in the same position and separate apart naturally.
    player_rez_position = new Vector3(player_rez_position.x + UnityEngine.Random.Range(0.04f, 0.99f), player_rez_position.y, player_rez_position.z + UnityEngine.Random.Range(0.04f, 0.99f));

    I have tested with a handful of clients spawning at same time and it some times works, but I am thinking there is another issue here causing this.
  • Kekora
    Kekora
    edited November 2016
    Options
    I just figured out that this issue may not be related to them being in the same position.

    I tested with 4 clients, put in wide random range values. so all clients sprinkle into the area not touching each other.
    on 2 clients it looks this way, with the positions looking identicle, at least 4+ meters apart.
    on 2 clients there are 2 players in the air jittering up and down.
  • Kekora
    Kekora
    edited November 2016
    Options
    I tried to make a script that turns on is-kinematic every 2 seconds for 1 frame, it stopped the jittering problem but breaks my jump ability horribly, haha, so I can't use that.
    I think this issue might be related to rigidbody or capsulecollider some how?

    I also noticed that if I see a jittering player and then bump into them, they settle down and stop shaking.




  • jeanfabre
    Options
    Hi,

    I suspect at this point that you have a conflict between the physics engine and the network controls.

    -- how do you synch position and rotation of your physics object?

    Bye,

    Jean
  • Kekora
    Kekora
    edited November 2016
    Options
    oh , yes , it would seem so :) thanks

    here is how I update position and rotation of other player...


    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { stream.SendNext(myDood.transform.position); stream.SendNext(myDood.transform.rotation); } else { position = (Vector3)stream.ReceiveNext(); rotation = (Quaternion)stream.ReceiveNext(); } } IEnumerator Alive() { while (isAlive) { float tmpDistance = Vector3.Distance(myDood.transform.position, position); if (tmpDistance > 25) { //print("snapping position, first position update"); myDood.transform.position = position; myDood.transform.rotation = rotation; } else { //print("blending"); myDood.GetComponent<Rigidbody>().MovePosition(Vector3.Lerp(myDood.transform.position, position, Time.deltaTime * lerpSmoothing)); myDood.transform.rotation = Quaternion.Lerp(myDood.transform.rotation, rotation, Time.deltaTime * lerpSmoothing); //myDood.transform.position = Vector3.Lerp(myDood.transform.position, position, Time.deltaTime * lerpSmoothing); //myDood.transform.rotation = Quaternion.Lerp(myDood.transform.rotation, rotation, Time.deltaTime * lerpSmoothing); } yield return null; } }

    I tried with both transform.position and GetComponent().MovePosition

    That code is inside the NetworkPlayer script, which sits on the top level of prefab, with the Photon View script observing it (Unreliable On change).
    The NetworkPlayer script is actually moving the deeper nested character that is dragged into the inspector as a Public GameObject.

    The nested character also has a Photon View script that is only watching it's Photon Animator View script, for the purpose of syncing mecanim.
  • jeanfabre
    Options
    Hi,

    and you have turned the rigidbody to is kinematic or disabled colliders? if you force the position and rotation on one scirpt while physics try to control it viy gravity and collision it will produce unwanted effects.

    also, it would be best to set position and rotation or rigidbody on FixedUpdate and not within a coroutine, this could be also the problem.

    Bye,

    Jean
  • Kekora
    Options
    hi,
    -gravity is always off for other players, just on for self.
    -colliders are on.
    -I tried turning on is-kinematic but then there was horrible lag and colliders were not movable, so i turned it off again.
    -so then i tried turning on just is-trigger for other players and the jittering problem goes away.

    but this then means players can't "bump" each other.

    ideally i would like players to bump and push each other. and soon I would like cars to hit cars, and cars hit players and the players go into ragdoll state.

    how do car games lerp remote players on the local screen while keeping colliders turned on? same problem surely?
  • jeanfabre
    Options
    Hi,

    yes, this is problematic indeed, doing complex physics interaction over a network. however, have you considered True Sync? this just came out and it meant to solve this problem with elegance and ease.

    https://www.photonengine.com/en-US/TrueSync
    It's actually not anymore in beta but on the asset store:
    https://www.assetstore.unity3d.com/en/#!/content/73228

    Bye,

    Jean
  • Kekora
    Kekora
    edited December 2016
    Options
    thanks for your help on this, much appreciated.

    I will look into TrueSync for the future. For now I will disable bumping.

    I guess we have solved this question.. client side physics + network updates was causing some conflict when setting position directly.