- Home /
Need Help Syncing door animations between all clients!
As the title says, I require a door to be synced on all the clients (door opening and closing animations).
I just need directions on how to do that, I have looked at a few tutorials for the NetworkAnimator, but all seem to be on animating the actual character movements and not things in the scene (non-player objects) which need to be animated across the network (e.g. the door). I was, however, able to get the door with the NetworkAnimator on it to allow the host (server & client) to sync to the client however when the client opens the door, it is not synced to the host.
I also attempted to throw the whole NetworkAnimator out and use Command/ClientRPC calls to open and close the door, but all I get is "Trying to send command for object without authority." for the client attempt and nothing when the host attempts to open it (both result in no door opening).
I would like it to use the NetworkAnimator (or another way to at least start animations synced across all clients and the host) as I have things like auto-turrets which are to be triggered to unfold and start firing at players and then fold back, so I want to apply the same 'knowledge' to that if possible.
Edit: Since the project is just a testing project, tell me where I should upload the files and I can.
This is the current setup I have (The game is basically the Network Tutorial but changed with a custom lobby networking script). Where this is at is, the host when opening the door will show the animation on both themselves and the other client, however when the client interacts with the door, only the client who interacted will see the animation and the host/other client can't.
Image showing setup in scene:
Image showing Hierarchy:
Image Showing the "doorTrigger" with the script attached:
Image showing the "door" components:
This is the script attached to the doorTrigger (The one which handles the animation (opening and closing) of the door object):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class NetworkedDoor : NetworkBehaviour {
public Animator animator;
bool currentDoorState;
void Start()
{
currentDoorState = false;
}
IEnumerator doorcontrolling()
{
if (Input.GetKeyDown(KeyCode.E))
{
if (currentDoorState)
{
closeDoor();
yield return new WaitForSeconds(1);
}
else
{
openDoor();
yield return new WaitForSeconds(1);
}
}
}
void OnTriggerStay(Collider col)
{
if (col.gameObject.tag == "Player")
{
StartCoroutine(doorcontrolling());
}
}
void openDoor()
{
animator.SetBool("DoorState", true);
currentDoorState = true;
}
void closeDoor()
{
animator.SetBool("DoorState", false);
currentDoorState = false;
}
}
Your answer
Follow this Question
Related Questions
How to create animations that can be edited with scripts in runtime? 1 Answer
Have some minor problems. Cant tell if its a script issue or a animator issue. 1 Answer
Enable animation C# 0 Answers
Why is my Character staying in Air Idle rather than Grounded Idle? 0 Answers
Rotation Y axis is bugged. 2 Answers