Animation not stopping when stationary

Options
I have a bobbing animation that plays when a player moves. This sets the Rigidbody to awake.
So I'm checking the Rigidbody.IsAsleep to stop the animation.

A player moves and stops fine. Rigidbody states change fine too with respect to whether the player is moving or not.

But there are times, randomly, even if my player stops moving and the Rigidbody is asleep, the animation still continues playing. When I disable the Photon Transform View, the animation stops. When I reenable it, the animation starts again despite the player is stationary.

I don't want to change and break anything in the Photon Transform View script. Does anyone with experience know why this is happening? Please help.

Comments

  • Tobias
    Options
    The PhotonTransformView is just a base implementation of how to sync the Transform of objects.
    We are happy if you copy and rename it to modify this into your own, perfectly working solution.

    I don't know how the PhotonTransformView affects the animation. Is this happening for the "remote" character? Or locally?
    Locally, it should not set any values but maybe the remote is triggered by updates coming in, which in turn triggers the Animation?

    Syncing animations can be tricky, because it is hard to "fetch" triggers, when they happen. The TransformView definitely has no idea of the Animation. Try the PhotonAnimationView.

    This might also be related to the Rigidbody. Did you set it to IsKinematic for the remote representation?
  • Vindorable
    edited May 2020
    Options
    Thank you for replying @Tobias :)

    I understand. But even if I was to modify it, I don't know where to being. I don't know what to look out for and how to optimize it. I'm learning from YouTube tutorials and the reason I picked up Pun is that firstly, it is high level and secondly, the support is solid from the community and admins.

    It's happening for the remote character. Local character is fine on either phone.

    I understand animation can be tricky. That is the main reason I went with an extremely simple approach that has no triggers.
    /// <summary>
    /// Manages the speed of the fins and tail and some simple animations.
    /// </summary>
    public class PlayerAnimationControl : MonoBehaviour
    {
        //private PlayerAbilityWalkSimple_Photon abilityWalk;
        private Rigidbody rb;
    
        [FoldoutGroup("Body")] public Animator bodyAnim;
    
        [FoldoutGroup("Fins")] public Animator leftFinAnim;
        [FoldoutGroup("Fins")] public Animator rightFinAnim;
        [FoldoutGroup("Fins")] public float finsSpeedIdle;
        [FoldoutGroup("Fins")] public float finsSpeedMove;
        [FoldoutGroup("Fins")] public float finsSpeedBoost;
    
        [FoldoutGroup("Tail")] public Animator tailAnim;
        [FoldoutGroup("Tail")] public float tailSpeedIdle;
        [FoldoutGroup("Tail")] public float tailSpeedMove;
        [FoldoutGroup("Tail")] public float tailSpeedBoost;
    
    
        // Get reference to the player movement script which is attached to the game object.
        //private void Awake() => abilityWalk = GetComponent<PlayerAbilityWalkSimple_Photon>();
        private void Awake() => rb = GetComponent<Rigidbody>();
    
    
        private void Update()
        {
            if (!rb.IsSleeping())
            {
                leftFinAnim.speed = finsSpeedMove;
                rightFinAnim.speed = finsSpeedMove;
                tailAnim.speed = tailSpeedMove;
            }
            else
            {
                leftFinAnim.speed = finsSpeedIdle;
                rightFinAnim.speed = finsSpeedIdle;
                tailAnim.speed = tailSpeedIdle;
            }
        }
    }
    

    The code above is the whole animation controller of the character. Nothing more to it.

    If you realized, I actually commented out a couple of lines that get the WASD input from the movement script. Because my movement script only affects if 'photonView.IsMine'. So I used the Ridgidbody asleep state instead.

    I didn't use 'IsKinematic' anywhere.

    -- Edit01 --
    Just in case if you want to look at my movement script (really basic, nothing fancy):
    https://pastebin.com/bak8LZeK
  • jeanfabre
    Options
    Hi,

    I think that problem here is not what you synch or how you sync it, it's how the animator component is setup to being with.

    A simple qpproach to remove any uncertainties is to create two local instance of your character, both non networked at all. make a script that makes one of this instance the "ismine" and the other the "Remote", and control the "ismine" with your inputs, then try to make the "remote" work the same, this doesn't involve any networking, just one component that makes the "remote" mimic the "ismine".

    this way, you can then completly rule out any effect bad networking strategy could have, once you have that working you will have at the point a character that is ready to be controlled remotly over the network.

    Bye,

    Jean
  • S_Oliver
    S_Oliver ✭✭✭
    edited May 2020
    Options
    Hi,
    the problem is you relay on Physics but only synchronize values like Position and Rotation.
    On one Client the Rigidbody is tryin to resolve a Collision or something but the TransformView forcing it still back to the same position. So localy the collision is maybe solved but on other clients not.

    That causes the
    rb.IsSleeping()
    
    to be true localy but on other clients maybe still false.
    Just get rid of this.
  • Vindorable
    Options
    S_Oliver wrote: »
    Hi,
    the problem is you relay on Physics but only synchronize values like Position and Rotation.
    On one Client the Rigidbody is tryin to resolve a Collision or something but the TransformView forcing it still back to the same position. So localy the collision is maybe solved but on other clients not.

    That causes the
    rb.IsSleeping()
    
    to be true localy but on other clients maybe still false.
    Just get rid of this.

    Thanks that actually worked! So the issue was related to physics.