Problem with interpolation and other noob problems

Options
I started using PUN two days ago by following this Tutorial:http://www.paladinstudios.com/2014/05/08/how-to-create-an-online-multiplayer-game-with-photon-unity-networking/

My problem is Im not following the tutorial step by step but Im adapting it to my game Ive been working on for some time now.

In my game the input manager and the script that moves the character are two separate objects, I dont use rigid bodies to move the character because I dont want physics so I thought I could just replace Rigidbody.position for gameObject.transform.position on OnPhotonSerializeView() but its not working, the character doesnt move so thats one problem.
using UnityEngine;
using System.Collections;

public class GamePadInputManager : Photon.MonoBehaviour {
    public GameObject PlayerCharacter;
    private Vector2 Aiming;
    private Vector2 Movement;
    private OnlineTankController _TankController;
    private CharacterController _Controller;
    /**Synchro**/
    private float lastSynchronizationTime = 0f;
    private float syncDelay = 0f;
    private float syncTime = 0f;
    private Vector3 syncStartPosition = Vector3.zero;
    private Vector3 syncEndPosition = Vector3.zero;
    // Use this for initialization
    void Start() {
        _TankController = PlayerCharacter.GetComponent<OnlineTankController>();
        _Controller = PlayerCharacter.GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update() { 
        if (photonView.isMine){
        PlayerInput();
        if (Aiming.y != 0 || Aiming.x != 0) {
            _TankController.RotateTurret(Aiming);
            _TankController.IsFiring = true;
        }
        else {
            _TankController.IsFiring = false;
        }
        if (Movement.y != 0 || Movement.x != 0) {
            _TankController.MoveCharacter(Movement);
            }   
        }
       else{
            SyncedMovement();
        
        }
    }
    void PlayerInput() {
        Aiming = new Vector2(Input.GetAxis("TurretX"), -Input.GetAxis("TurretY"));
        Movement = new Vector2(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"));
    }
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
        if (stream.isWriting) {
            stream.SendNext(PlayerCharacter.transform.position);
        }
        else {
            syncEndPosition = (Vector3)stream.ReceiveNext();
            syncStartPosition = PlayerCharacter.transform.position;

            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;
        }
    }
    private void SyncedMovement() {
        syncTime += Time.deltaTime;
        PlayerCharacter.transform.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay);
    }
}
(some platform specific code has been taken out becuase Im under DNA with a console manufacturer)

second problem I need my characters to move the turret (they are tanks) and shoot, in the inputmanager this is done by running RotateTurret() on the script that moves the character (TankController) how can I do this over the network?


third problem, Ive read that people usually instantiate bullets but I dont instantiate bullets because of memory constritions of the platform I have an object pool manager and I reposition and activate/ objects instead of Instantiating/destroying them, how can I run these methods over the network?

Thank you in advance!

Comments

  • I fixed the first problem my self by changing "PlayerCharacter.transform.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay);" to "_Controller.Move (Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay));"

    Is there any way I can send the two Vector2 (Aiming , Movement) to the other players tank instead? it think it would be faster than moving the tank directly also that way I could also fix the other problems because the shooting and the tanktrack animation (its not actually an animation but a shader that scrolls the tanktrack texture) are tied with those Vector2
  • vadim
    Options
    Looks like you need RPC's for 2nd and 3rd problems.
    They are pretty simple and you can easy get an idea from any demo bundled with PUN or from this tutorial http://doc.exitgames.com/en/pun/current ... c317517606