# Client prediction

**URL:** <https://community.coherence.io/t/client-prediction/580>\
**Category:** Help\
**Created:** [September 2, 2024, 1:15am UTC](https://community.coherence.io/t/client-prediction/580 "2024-09-02T01:15:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![GhazyAzhar](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@GhazyAzhar](https://community.coherence.io/u/GhazyAzhar)\
**Post date:** [September 2, 2024, 1:15am UTC](https://community.coherence.io/t/client-prediction/580/1 "2024-09-02T01:15:02Z")

</div>

which approach I should take to make the remote client responds faster.  
The case is I have a player object that is throwing an explosion to another client, on the local screen, the impulsion effect of the remote client is delayed, meanwhile on the remote client’s screen, it’s pretty much seems normal.

This is what happened currently in my script:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/00a1cfe8e5b3b7d01002d4adaad59db3cb18d87d.png)

I have a I learned that I can use a simulator cloud to sync every client, and also one Coherence’s advice me to use client prediction without simulator (or client authoritative setup).

But I couldn’t quite find how to exactly do that client prediction with client authoritative setup. I mean, which variable I should enable client prediction on coherence config? I am interested to use this approach.

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![brit](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/brit/32/34_2.png) [@brit](https://community.coherence.io/u/brit)\
**Post date:** [September 2, 2024, 11:02am UTC](https://community.coherence.io/t/client-prediction/580/2 "2024-09-02T11:02:12Z")

</div>

Hi, thanks for taking the time to make a thread and add a video. A quick question before we dig in - is this using coherence Cloud or is it using a local replication server?

---

<div class="post-metadata">

**Author:** ![brit](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/brit/32/34_2.png) [@brit](https://community.coherence.io/u/brit)\
**Post date:** [September 2, 2024, 11:26am UTC](https://community.coherence.io/t/client-prediction/580/3 "2024-09-02T11:26:07Z")

</div>

A coworker pointed out that it doesn’t appear that you’re running a local RS from your taskbar, so assuming you’re doing this over coherence Cloud, the “lag” you’re seeing from one client to another is expected and yes, client prediction or server simulation is one possible solution if you want to alleviate it.

My recommendation in terms of complexity is to do some simple client prediction:

- You are already displaying the arc the bomb is going to throw in, meaning you have some sort of prediction of it’s path
- At the moment of release, determine where and what it’s going to collide with and send this information to all clients, including a universal timestamp of when things will happen
- All clients then perform the necessary explosions/effects

You can use the “prediction” toggle in coherence on the position of the players. You will need to write some code to reconcile the prediction and the actual data coming in, and you will need to play with the frequency of reconciliation to make sure things aren’t jittery. See [Server-authoritative setup | Unity Multiplayer SDK Documentation | coherence](https://docs.coherence.io/manual/authority/server-authoritative-setup#client-side-prediction)

I will conclude with, although you are seeing both clients on the same machine and it’s very obvious, the amount of lag I’m seeing in the video may be playable between two players across the internet without an issue.

---

<div class="post-metadata">

**Author:** ![brit](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/brit/32/34_2.png) [@brit](https://community.coherence.io/u/brit)\
**Post date:** [September 2, 2024, 11:29am UTC](https://community.coherence.io/t/client-prediction/580/4 "2024-09-02T11:29:33Z")

</div>

Oh, an important note about the above solution is that all of simulation should be happening on a single client - e.g. one client has authority over the objects and the other clients are predicting input and reconciling

---

<div class="post-metadata">

**Author:** ![GhazyAzhar](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@GhazyAzhar](https://community.coherence.io/u/GhazyAzhar)\
**Post date:** [September 2, 2024, 1:47pm UTC](https://community.coherence.io/t/client-prediction/580/5 "2024-09-02T13:47:18Z")

</div>

Hi, we are currently using coherence cloud!

---

<div class="post-metadata">

**Author:** ![GhazyAzhar](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@GhazyAzhar](https://community.coherence.io/u/GhazyAzhar)\
**Post date:** [September 3, 2024, 12:30pm UTC](https://community.coherence.io/t/client-prediction/580/6 "2024-09-03T12:30:58Z")

</div>

does this means I could choose the rigidbody of the player object into “leave as is” or dynamic? So the local client could simulate the impulse of remote clients from the explosion locally then the remote client is reconciling?  
or am I wrong. I still couldn’t quite understand about the simulating the remote client’s impulsion in local

---

<div class="post-metadata">

**Author:** ![brit](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/brit/32/34_2.png) [@brit](https://community.coherence.io/u/brit)\
**Post date:** [September 3, 2024, 3:33pm UTC](https://community.coherence.io/t/client-prediction/580/7 "2024-09-03T15:33:28Z")

</div>

Taking a step back from the thread happening in Discord - let’s start with your initial post.

Perhaps the delay seen when the impluse happens is due to interpolation.

Impulse generates instant force and motion, but our default interpolation will attempt to smooth out any instant movements.

Can you please try out different interpolation methods to see if anything gets you want you want?

Here are our docs on interpolation:

> **[Interpolation | Unity Multiplayer SDK Documentation | coherence](https://docs.coherence.io/manual/networking-state-changes/interpolation)**

---

<div class="post-metadata">

**Author:** ![GhazyAzhar](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@GhazyAzhar](https://community.coherence.io/u/GhazyAzhar)\
**Post date:** [September 3, 2024, 6:01pm UTC](https://community.coherence.io/t/client-prediction/580/8 "2024-09-03T18:01:35Z")

</div>

Actually i tried to set the interpolation to none, and it gets bit better in terms of latency. I could balance it out, but I still wonder about this sentence you have talked in discord

> the remote client moving due to explosion should be a result of position sync. the explosion and how much they move should happen on the client with state authority.

so this means that sending command to other client to move (as the result from explosion impact) is bad, so how to move the other client by explosion in the most effective way? I have this script to move any entities with rigidbody, the explosion and animations are fine, but the movement of other client is delayed just like the first video, and this time there is no command at all.

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/bf296a081a70e448b9be44712c1fc74872ae31ee.png)

also does this mean that the local client has to take the remote player’s authority for the movement caused by impulsion?

---

<div class="post-metadata">

**Author:** ![brit](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/brit/32/34_2.png) [@brit](https://community.coherence.io/u/brit)\
**Post date:** [September 3, 2024, 7:24pm UTC](https://community.coherence.io/t/client-prediction/580/9 "2024-09-03T19:24:21Z")

</div>

Ah, my reply there was assuming you were using a client prediction host/server setup, and I realized that wasn’t necessarily the case based on your initial video.

But, ultimately if interpolation settings are not getting you to where you like, then I think yes you can move towards server simulation as you mentioned in Discord.

I would follow the guide from the beginning for the Server-authoritative setup: [https://docs.coherence.io/manual/authority/server-authoritative-setup](https://docs.coherence.io/manual/authority/server-authoritative-setup)

And see where that gets you.

In this setup, yes: one server or host has full input authority over all players, and rigid bodies and physics should be disabled for them on other clients. You can then use local client prediction and reconcile that with what you get from the server. You can continue to use commands as a prediction element to impulse players and reconcile that with the server’s data.

---

<div class="post-metadata">

**Author:** ![GhazyAzhar](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@GhazyAzhar](https://community.coherence.io/u/GhazyAzhar)\
**Post date:** [September 4, 2024, 4:40am UTC](https://community.coherence.io/t/client-prediction/580/10 "2024-09-04T04:40:23Z")

</div>

Thank you for the suggestion, we’ll implement the simulator.

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [September 9, 2024, 3:04pm UTC](https://community.coherence.io/t/client-prediction/580/11 "2024-09-09T15:04:15Z")

</div>

> [@GhazyAzhar](#):
>
> The case is I have a player object that is throwing an explosion to another client, on the local screen, the impulsion effect of the remote client is delayed, meanwhile on the remote client’s screen, it’s pretty much seems normal.

Hey GhazyAzhar. I just want to add something that I happened to notice in the first code you posted. This is in addition to the suggestions Brit made, just something to help you understand more how to code these behaviours.

The “issue” I noticed is that in that code, you send a command to `MessageTarget.All` to activate the gameplay effect of detonating the bomb.  
This is not wrong in itself, but… you also do a couple of things in there that only the authority should do.

Like for instance, calling `Destroy` on the object. You probably got some error message from coherence for that, because only the authority of the bomb should be destroying a network entity. By doing so, the entity will be automatically destroyed (by coherence) on all other connected clients.

The other thing you do is call `ApplyExplosion()` which in turn does a search for colliders, and applies a force. You can imagine that on every computer where the bomb explodes, all remote players will be (or, should be) kinematic rigidbodies. So when the bomb finds them and applies a force, nothing happens.

While the first produces an error in the console, the second is a harmless problem (just a bit of performance lost). However, I thought it could be useful to point these things out so you can understand better how to structure things for networking.

There is no 1 right way to structure these things, but it’s good to always keep in mind who’s the authority for an object and separate behaviour that the authority should run (like destruction, movement, etc), from the one the others should run (like particles, visuals, etc.)

On these topics, you could take a look at the pages I wrote for our Campfire demo.

> **[Remote interactions: Chairs | Unity Multiplayer SDK Documentation | coherence](https://docs.coherence.io/getting-started/samples-and-tutorials/campfire-project/remote-interactions-chairs)**

> **[Remote interactions: Trees | Unity Multiplayer SDK Documentation | coherence](https://docs.coherence.io/getting-started/samples-and-tutorials/campfire-project/remote-interactions-trees)**

> **[Playing audio and particles | Unity Multiplayer SDK Documentation | coherence](https://docs.coherence.io/getting-started/samples-and-tutorials/campfire-project/playing-audio-and-particles)**

They don’t cover your case exactly, but they can be inspiration.

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [November 29, 2024, 7:43am UTC](https://community.coherence.io/t/client-prediction/580/12 "2024-11-29T07:43:35Z")

</div>

hi GhasyAzhar well if your question has been solved just select a solution on the reply that solved it

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/b3aa79eb9519fac7aad7eba18f15a1e8ce60f6e2.png) [@system](https://community.coherence.io/u/system)\
**Post date:** [February 27, 2025, 7:43am UTC](https://community.coherence.io/t/client-prediction/580/13 "2025-02-27T07:43:37Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
