miwarnec / uMMORPG

4 stars 0 forks source link

Corpses don't hide anymore #14

Closed wovencode closed 5 years ago

wovencode commented 5 years ago

Versions (please complete the following information)

Describe the bug Corpses of dead monsters (and in fact all kinds of networked objects using a proximity grid checker) are not hidden when they die. You can see that on "Network Proximity Grid Checker" the "Force Hidden" Flag is set on the server, but it has no effect on clients.

Important Note: It works in Host+Play but not as Server and separate Client !!!

To Reproduce Simply import latest, unmodified uMMORPG3d into unity and kill a few skeletons. You can even set "death time" to 0. Their corpses stay around forever.

Expected behavior Corpses should hide after death time elapsed.

System (please complete the following information):

unknown

Ghetaldus commented 5 years ago

Just found where bug is. In NetworkProximityGridChecker.cs on line 124 you are doing "return true" when checking forceHidden. It should be false as it is in NetworkProximityChecker.cs in Mirror. I have just tested changing it to true and corpses disappear fine now.

gummby8 commented 5 years ago

Having the same issue with 2d I think he got his bool mixed up. It is currently set to false, it should be true

Should look like this, at least on UMMORPG2d

// called when a new player enters
public override bool OnCheckObserver(NetworkConnection newObserver)
{
    if (forceHidden)
        return true;

    // calculate projected positions
    Vector2Int projected = ProjectToGrid(transform.position);
    Vector2Int observerProjected = ProjectToGrid(newObserver.playerController.transform.position);

    // distance needs to be at max one of the 8 neighbors, which is
    //   1 for the direct neighbors
    //   1.41 for the diagonal neighbors (= sqrt(2))
    return Vector2Int.Distance(projected, observerProjected) <= Mathf.Sqrt(2);
}

public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initial)
{
    // only add self as observer if force hidden
    if (forceHidden)
        return true;

    // add everyone in 9 neighbour grid
    Vector2Int current = ProjectToGrid(transform.position);
    HashSet<NetworkConnection> hashSet = grid.GetWithNeighbours(current);
    observers.UnionWith(hashSet);

    // always return true when overwriting OnRebuildObservers so that
    // Mirror knows not to use the built in rebuild method.
    return true;
}
miwarnec commented 5 years ago

fixed in latest version, thanks for reporting

Ghetaldus commented 5 years ago

Well it is not fixed for uMMORPG in latest version. You have fixed it in NetworkProximityChecker.cs in Mirror. uMMORPG uses NetworkProximityGridChecker.cs that is not part of Mirror and that one have same error as well.