Object with PhotonView appear at 0/0/0 on Start

Options
Hi everybody ! :) I have some trouble with object with PhotonView

-I set 5 monster on the map with photonview and Smoothmovement script, But when i launch the game with the master Client, all monsters appear on 0/0/0
i have no object with this position except the player , and no script attach to my monster with this position ...

-My monster are not "instanciate" and i use RPC to sent their position to new player connected ( I modified the "pickeup scrip system and this part work perfectly)

-They have no parents and they have their own position set .

So i don't understand what is happening :/

Tanks if someone can try to help me i will really appreciate! :*
I wish you a good night!

Comments

  • Bunzaga
    Options
    Hey, it is probably the initial value you have set in their PhotonView. For example, most people have something like ... private Vector3 streamedPosition; That's 0,0,0 by default.

    So it sounds like, their initial position is being set to 0,0,0, then you send their position, which in turn moves them to 0,0,0. Check through the logic order of execution, and see if there is a way to not send the RPC until after their position has been first established. For an example, in my PhotonView Read Stream, I have:
    protected override void ReadStream(PhotonStream stream)
    {
        // local stuff
        if (_agent != null)
        {
            _syncStartPosition = _agent.transform.position;
        }
        _receivedNetworkUpdate = true;
    
        // sync stuff
        _syncEndPosition = (Vector3)stream.ReceiveNext();
        _userSpeed = (float)stream.ReceiveNext();
        _destination = (Vector3)stream.ReceiveNext();
        _stoppingDistance = (float)stream.ReceiveNext();
    
        if (_agent != null)
        {
            bool agentEnabled = (bool)stream.ReceiveNext();
            if (agentEnabled)
            {
                _obstacle.enabled = false;
                _agent.enabled = true;
            }
            else
            {
                _agent.enabled = false;
                _obstacle.enabled = true;
            }
        }
    }
    Ignoring most of that, take special note of the line "_receivedNetworkUpdate = true;"

    Now in my interpolation:
    protected override void SyncedUpdate()
    {
        if(_receivedNetworkUpdate == false) { return; }
        if (_firstTake)
        {
            _firstTake = false;
            _agent.transform.position = _syncEndPosition;
            _userEntityView.transform.position = _syncEndPosition;
            return;
        }
    
        if (!_agent.isOnNavMesh) { return; }
        if (!_agent.enabled) { return; }
    
        _agent.stoppingDistance = _stoppingDistance;
        _agent.SetDestination(_destination);
        _agent.speed = _userSpeed;
        
    
        if (_userSpeed > 0)
        {
            _distance = (_syncEndPosition - _syncStartPosition).magnitude;
    
            if(_distance > 3.0f)
            {
                // just warp if too far
                //transform.position = _syncEndPosition;
                // Bunzaga keep looking into a better algorithem than this...
                _agent.transform.position = _syncEndPosition;
                _userEntityView.transform.position = _syncEndPosition;
            }
            if(_distance > 0.25f)
            {
                _agent.transform.position = Vector3.Lerp(_syncStartPosition, _syncEndPosition, NetworkTime.Alpha);
            }
            _userEntityView.transform.position = Vector3.Lerp(_userEntityView.transform.position, _agent.transform.position, Time.deltaTime * 5);
        }
    }
    See how I first check, if _receivedNetworkUpdate? If it's false, I don't move the guy, if I did get it, but this is the 'first take', I just set him to the goal, with no interpolation... this is probably where your guys are being set to 0,0,0. So perhaps check to make sure you've gotten that first positional data, before you send them...

    Anyway, this is what helped me, good luck.
  • redskry
    Options
    Thx a lot! It's perfect!! i really appreciate!