![]() ![]() PPS: When I use the interpolation, it flickers a lot but I can see that the position is right, it is not lagging like before, so the best would be to resolve how to make my interpolation and not removing it. PS: I tried to lerp only if syncTime/syncDelay < 1.0 to be sure I don't extrapolate, but it did not change a thing. Thank you very much for your help in advance! In any case, would you have an idea on how to fix this? Since my method is called from FixedUpdate, I am wondering if the gameobject is simple refreshing so much that I don't even see it. SyncStartPosition = rigidbody2D.position īut now the other player is invisible when not moving, and is visible but flickering a lot when moving (flickering so much I hardly see it). SyncDelay = Time.time - lastSynchronizationTime Rigidbody2D.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay) Īnd using this method: void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) I tried to follow the tutorial, adding void FixedUpdate() Without interpolation, I have too much latency issues (the other player is "lagging" a lot). I followed this tutorial which is really nice and everything worked but one thing, the interpolation. Remember, only the owner is supposed to be able to move the object, the other players are listening in for coordinates. HealthBarLength = (float)value / (float)value2 / 5.1f Īlso, a small tip for those who get errors when setting the exSprite Camera to None You need to update your ex2D plugin.I'm trying to get my basic game online and got into some problems. Also, network games have some psycho logic to think through, try to always rather use NetworkView.isMine to determine who is the owner of the object and who isn't. Public void Update_Health(int value, int value2) NetworkView.RPC("Update_Health", RPCMode.AllBuffered, hp, maxHP) In hopes that this can help anyone looking for how to do health bars over a network, here is the final code I'm using: using UnityEngine By clicking on the texture and setting the ex2D exSprite's Camera to None, I can now see both bars being updated / scaled properly. Because it was set to my camera on player instantiate, it was only seeing my bar through my camera, thus not updating the other bar via client / server side. On each exSprite there is a camera view, set to the user's main camera. The problem was actually with the ex2D plugin I was using for the health bar. The code itself was working great (and you're right pek, that bar parameter was just tedious). I've also tried this, with no luck either: void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) HealthBar.scale = new Vector2(bar.x, bar.y) Public void Update_Health(int value, int value2, Vector3 bar) NetworkView.RPC("Update_Health",RPCMode.All, hp, maxHP, bar) Public void Update_HP(int hp, int maxHP, Vector3 bar) If isMine is true, the instance in the main one, it will send updates to its ghosts. not the gameobject or networkplayer Thank you, appels NetworkView can have mulitple instances spreading on all net peers, and there's only one instance which is the main instance, others are ghosts. Update_HP(health, maxHealth, healthBar.scale) isMine refers to the networkView component on the object. HealthBar.scale = new Vector2(healthBarLength, ) HealthBarLength = (float)health / (float)maxHealth / 5.1f ![]() I did the following code and it doesn't work: void Start() When I send the RPC, It does change the other player's health value, but does nothing to the scale. This works by providing a NetworkView component, which can serialize object. The player who sends the call has their bar changed though. The problem is that even though I send the information through the network and it's received, the actual physical bar doesn't change in scale. That way you can just look at another player and see their health bar. In my game, the characters have health bars over their heads that are supposed to update for the entire server. I'm having a difficult time getting my health bar to sync through the server on Unity using RPCs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |