syncing animations
whats the best way to sync an animation, my setup is: an AI spawner spawns multiple AIs that move to the closest block and start destroying it, and im not quite sure on the best way to sync the destroying animation.
also, when the ai is spawned, i made it so if you didnt create the room, the ai script gets disabled (this way, only the server owner manages the ai)
4 Replies
Hi @MasterOX 水. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Normcore, you can synchronize animations across all clients using the synchronized clock. This clock is set to match the room server's clock exactly with no added latency. Once connected to a room, the room time is available via the
realtime.room.time
property.
Here's an example of how to use it:
In this example, the StartStopwatch()
method sets the start time to the current room time. The time
property then calculates how much time has passed since the stopwatch was started. You can use a similar approach to synchronize your animations.
For your AI spawner, you can use the RealtimeTransform
component to synchronize the position, rotation, and scale of your AI entities. This component has properties like syncPosition
, syncRotation
, and syncScale
that you can use to control what aspects of the transform are synchronized.
As for disabling the AI script for clients who didn't create the room, you can use the RealtimeComponent
's RequestOwnership()
method to request ownership of the component. If the client is not the owner, you can disable the AI script.
Here's an example:
In this example, realtimeComponent.isOwnedLocally
checks if the client is the owner of the component. If not, it disables the AI script.
Please note that these are just examples and you may need to adapt them to fit your specific use case.
Sources:
- Timers + Synchronized Playback (https://normcore.io/documentation/guides/recipes/timers-and-synchronized-playback)
- RealtimeTransform (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeTransform)
- IRealtimeComponent (https://normcore.io/documentation/reference/classes/Normal.Realtime.IRealtimeComponent)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below
not very helpful
the stopwatch example shows you how to sync time which you can use for animation syncing but if you just want to trigger an animation to play when the wall health reaches 0 and you're not bothered if the animation syncs up 100% across clients you can just sync wall health and when it reaches 0 play the animation locally.