Problem with Angry Bots Multiplayer

So I making a game, using Angry Bots Multiplayer as example. I Instantiate player prefab with PhotonView attached, and made PhotonView observe Movement script, same as it is in Angry Bots. I added this code to the script:
function OnPhotonSerializeView (stream : PhotonStream,  info : PhotonMessageInfo)    
    {
        OnPhotonSerializeViewBase(stream, info);
    }
This movement script extends MovementMotor script:
class MovementMotor extends Photon.MonoBehaviour {

// The direction the character wants to move in, in world space.
// The vector should have a length between 0 and 1.
@HideInInspector
public var movementDirection : Vector3;

// Simpler motors might want to drive movement based on a target purely
@HideInInspector
public var movementTarget : Vector3;

// The direction the character wants to face towards, in world space.
@HideInInspector
public var facingDirection : Vector3;


 function OnPhotonSerializeViewBase (stream : PhotonStream,  info : PhotonMessageInfo)    
    {
       
    	if (stream.isWriting)
        {            
    		//We own this player: send the others our data
    		stream.SendNext (transform.position);
    		stream.SendNext (transform.rotation); 
        }
        else
        {        	
            //Network player, receive data			
            correctPlayerPos = stream.ReceiveNext();
            correctPlayerRot = stream.ReceiveNext();
         }
    }
    
    
    //
    //  TODO: fix constant movement!
    //
    //

    private var correctPlayerPos : Vector3= Vector3.zero; //We lerp towards this
    private var correctPlayerRot : Quaternion = Quaternion.identity; //We lerp towards this

    function Update()
    {		    
        if (!photonView.isMine)
        {
        	if(correctPlayerPos==Vector3.zero) return;
        	
            //Update remote player (smooth this, this looks good, at the cost of some accuracy)
            if (Vector3.Distance(correctPlayerPos, transform.position) < 4)
            {
                transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
                transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
            }
            else
            {
                 transform.position =  correctPlayerPos;
                 transform.rotation = correctPlayerRot;
            }
        }
    }
    
    
    
 }
But when I starting a test game, players are not sending their position to other peers! I tried to set PhotonView to observe only position and rotation, not the script, and it worked, but not so smooth as in the original AngryBots.
What am I missing? I am kinda new with Photon, so it could be really obviously

Comments

  • All out scripts are C#. You might need to put them into a "plugin" folder, directly in the assets folder.
    Otherwise, your Unity Script can't be called.
  • Are you using the exact same scripts as in the angry bots demo? Please verify.
    -Which- movement motor are you using ? (the "child" class of the MovementMotor)
Sign In or Register to comment.