Understanding Ownership

Options
Great plugin! I have been able to prototype quickly with this and this solution appears to be ideal for my needs! Thanks much to the dev team!!! I have been cruising right along and ran into a snag and I can't figure out how best to deal with this.

Currently making a two person zombie game. I have both players instantiating and am using PhotonView to sync animations and transforms.

There are zombies (BRAINS!)

Zombies are in the game scene as objects (not instantiated) and are triggered two ways. One, they have a collider that is a trigger. If either player enters the trigger, the zombie (which also has a PhotonView component) moves and animates. Both players see it. So far so good.

The other way they are triggered is if they are shot.

To shoot I am using a raycast script on the gun. It sends damage data and the root of the gun (player) to the zombie script. On receiving this data the zombie script calls a remote procedural call that sets the zombies target to the game object and applies damage.

If either player enters the trigger zone of the zombie, it follows the player, all animations and transforms work as expected, both players can damage and kill the zombie and see animations. So far so good.

However, if the second player to join shoots the zombie, it sets this player as the appropriate target, but it will not move. It animates, but doesn't move. I think the other players PhotonView is controlling the zombies position, because if I uncheck the zombie's -PhotonView in the editor, it approaches player two as expected.

Couple of things where this might be getting tripped up. One, you can't pass GameObjects with [PunRPC] - so I am setting a temporary object in the zombie script that calls the RPC, then setting the target within the call.

This also might be a question of ownership, although I confess ownership confuses me a bit. I thought it was the role of the PhotonView to track the position and animations of objects and make sure that all clients would be updated. I have read through the docs, but I am not really getting when fixed, takeover and request would be helpful or necessary. if it is an ownership thing, why would the zombie work as expected if triggered, but not shot?

Here is the code where the zombie calls the RPC

public void Damage(float damageAmount, GameObject target)
{
tempObject = target;
pv.RPC("applyDamage", PhotonTargets.All, damageAmount);
}

applyDamage applies damage to the zombie and sets the target to tempObject;

Any insight is super helpful!

Comments