LogoLogo
HomeOnline DashboardAPIDiscordForums
SDK 0.4.14
SDK 0.4.14
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Features and Roadmap
    • Requirements
  • Get Started
    • Install coherence
    • Scene setup
    • Prefab setup
    • Build and run
    • Baking and code generation
    • Create a free account
    • Deploy and share
  • Authority and communication
    • How authority works
    • Authority transfer
    • Commands
    • Server-side and input queues
    • Animations
  • Persistence
    • Overview
    • Configuring persistence
    • Storage
    • Example – A global counter
  • Optimization
    • Overview
    • Simulation frequency
    • Areas of interest
    • World size
    • Level of detail
    • Interpolation
    • Extrapolation
  • Connected entities
    • Overview
    • Entity references
    • ConnectedEntity component
    • Parent-child relationships
  • Simulators
    • Overview
    • Client vs. simulator logic
    • Build and deploy
    • Simulator load balancing
  • Tutorial project
    • Get the Tutorial Project
    • Start Tutorial
      • 1. Transforms
      • 2. Physics
      • 3. Persistence
      • 4. Animation and Variables
      • 5. AI Navigation
      • 6. Network Commands
      • 7. Network Events
  • Game Services
    • Game account
    • Key-value store
    • Matchmaking
  • API reference
    • Network SDK
      • CoherenceSync
      • MonoBridge
      • LiveQuery
      • Archetype
      • Sample UI
      • Settings Window
    • Cloud API
      • API tokens and keys
      • Server discovery
      • Game account
      • Key-value store
      • Matchmaking
    • Replication Server
    • Simulation Server
    • Entity Component System
      • Network Entities and Components
  • Schema reference
    • Overview
    • Specification
    • Field Settings
    • Archetypes and LOD-ing
  • Resources
    • Downloads
    • Video Tutorials
    • Glossary
    • CLI Utilities
    • Helper Scripts
    • Troubleshooting
  • Community
    • Discord
  • Additional information
    • Pricing
    • SLA
    • Unreal Engine support
    • Peer-to-Peer (P2P)
    • Known Issues
    • Version History
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Authority and communication

Animations

Last updated 4 years ago

Was this helpful?

coherence doesn't replicate Animator state, but its parameters. Latency can create scenarios where different clients reproduce different animations. Take this into account when working with Animator Controllers that require precise timings.

Unity Animator's parameters are bindable out of the box, with the exception of triggers.

Triggers

using UnityEngine;
using Coherence.Toolkit;
using System.Collections.Generic;

public class JumpController : MonoBehaviour
{
    static List<CoherenceSync> instances = new List<CoherenceSync>();

    CoherenceSync coherenceSync;
    Animator animator;

    void Awake()
    {
        coherenceSync = GetComponent<CoherenceSync>();
        animator = GetComponent<Animator>();
    }

    void OnEnable()
    {
        instances.Add(coherenceSync);
    }

    void OnDisable()
    {
        instances.Remove(coherenceSync);
    }

    void Update()
    {
        if (!coherenceSync.isSimulated)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            MakePlayerJump();
        }
    }

    void MakePlayerJump()
    {
        animator.SetTrigger("Jump");
        // TODO move your character up
        NotifyJumpOverNetwork(coherenceSync);
    }

    // bind to this method via the Bindings window
    public void PlayJumpAnimation(CoherenceSync target)
    {
        var animator = target.GetComponent<Animator>();
        animator.SetTrigger("Jump");
    }

    void NotifyJumpOverNetwork(CoherenceSync whoJumped)
    {
        foreach (var s in instances)
        {
            if (!s || s == whoJumped)
            {
                continue;
            }

            s.SendCommand("JumpController.PlayJumpAnimation", whoJumped);
        }
    }
}

Now, bind to PlayJumpAnimator.

Triggers can be invoked over the network using and events. Here's an example where we inform networked clients that we have played a jump animation:

Since we don't have support for events yet, here we use and entity references to notify other clients about our entity performing a jump.

commands
command broadcasting
Speed and Pose parameters are available bindings on CoherenceSync