Search Unity

Any way to reset the networkTransform values?

Discussion in 'Multiplayer' started by redkatana, Jan 13, 2016.

  1. redkatana

    redkatana

    Joined:
    Oct 1, 2015
    Posts:
    2
    Hi all,

    I'm currently prototyping a moba in unet and having some difficulties trying reset the networkTransform values.

    Let me explain the situation.

    1.- When a "minion" (is a pooled GameObject) die in "a" position/rotation, I "release" that one (I disable the gameObject and mark it as usable for the pool system).
    2.- I wait the respawn interval.
    3.- Then I spawn the "minion" in "b" position/rotation, making that gameObject enable and used.

    The problem is when I spawn that "minion" again, the targetSyncPosition, and the targetSyncRotation3D has the "a" position/rotation value so in the client will teleport from "b" to "a" and then when recieve from the server the new targetSyncPosition it will make another teleport from "a" to "b".

    So there is any way to reset the NetworkTransform?

    Thanks for read.
     
  2. BGog

    BGog

    Joined:
    Feb 10, 2014
    Posts:
    10
    Did you ever figure this out? I have a problem where I change the authority from client to server and it keeps the targetsync positions/velocity etc. When the server gets authority back and sends an update the velocity becomes huge for one or two frames. The actual difference in position is minimal but I believe that the velocity is being calculated based on the difference between current position and the one last stored in targetsyncposition.

    This causes a huge one frame jump of object position when authority is passed back to the server.
     
  3. redkatana

    redkatana

    Joined:
    Oct 1, 2015
    Posts:
    2
    My solution was download the UNET repository and add setters in the NetworkTransform/NetworkTransformChild to the following properties:

    targetSyncPosition
    targetSyncRotation3D
    targetSyncVelocity

    And then build the my own dll.
     
  4. Joskman

    Joskman

    Joined:
    Jan 6, 2019
    Posts:
    5
    EDIT: Obsolete answer, only valid and tested for Mirror v42.2.12

    Original answer:
    Same problem with Mirror and solved with a dirty quick solution: Locate file "NetworkTransformBase.cs" and find theses declarations:
    Code (CSharp):
    1. DataPoint start;
    2. DataPoint goal;
    Make them public (well, I beg you to make it a setter):
    Code (CSharp):
    1. public DataPoint start;
    2. public DataPoint goal;
    Then in your code, in the line where your Server object regains Authority back (or control in some other way), set your "start" and "goal" properties of the NetworkTransform component.

    For example, in a 2D game where ball "teleports" strangely when server regains Authority, the solution is (code in Server):
    Code (CSharp):
    1. ballId.RemoveClientAuthority();
    2. NetworkTransform nt = GetComponent<NetworkTransform<>();
    3. nt.start = nt.goal;
     
    Last edited: Sep 12, 2021