CorrectPlayerPos = 0,0,0

Hi, I am trying to use this code to make the players positions smooth...
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if(stream.isWriting){
		stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
		}
		else{
			correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();
			
		}
	}


so, I have the variables for correctPlayerPos and correctPlayerRot. I do vector3.lerp to lerp from the players current positions to the "CorrectPlayerPos" and "CorrectPlayerRot", but when I look at the variables, they're always set to 0.

Please help....

I have it in my Player_Network script.

Here it is.

using UnityEngine;
using System.Collections;

public class Player_Network : Photon.MonoBehaviour {
	
	public GameObject Cam;
	public PlayerWeapos Weaps;
	public Transform Weap1;
	public CharacterMotorDB Controller2;
	public FPSInputControllerDB Controller1;
	public GameObject PublicPlayer;
	public MouseLookDB PlayerLook;
	private MouseLookDB CamLook;
	public GameObject gun;
	public PlayerHealth HealthCode;
	public GameObject Class;
	public LocalPlayerClassNew Class1;
	public RecieveXP xp;
	public DamageHud hithud;
	//public EnterJet entre;
	public Material ArmMaterial;
	public Texture AlliesTexture;
	public Texture AxisTexture;
	private bool Crouch;
	public ThirdPersonAudio TPA;
	public Vector3 correctPlayerPos; //We lerp towards this
    public Quaternion correctPlayerRot; //We lerp towards this
	//public Scoreboard Board;
	
	
	// Use this for initialization
	void Start () {
		CamLook = Cam.GetComponent<MouseLookDB>();
		//Weaps = transform.FindChild("WalkStuff").GetComponent<PlayerWeapos>();
		//Weap1 = transform.FindChild("WalkStuff");
		//Class = GameObject.Find("Code_game");
		Class1 = GameObject.Find("Code_game").GetComponent<LocalPlayerClassNew>();
		
		Rigidbody[] bodys = PublicPlayer.GetComponentsInChildren<Rigidbody>();
			foreach(Rigidbody body in bodys){
				body.isKinematic = true;
			}	
	}
	
	
	
	// Update is called once per frame
	void Update () {
		
		//if(Class1.isSniper == true){
		//	Weaps.Primary = Weap1.FindChild("Sniper").gameObject;
		//	Weaps.Primary = Weap1.FindChild("Scar").gameObject.active = false;
		//}
		//if(Class1.isAR == true){
		//	Weaps.Primary = Weap1.FindChild("Scar").gameObject;
		//	Weaps.Primary = Weap1.FindChild("Sniper").gameObject.active = false;
		//}
		
		Weaps.Secondary = Weaps.ListOfSideArms[Class1.selecteds];
		if(Class1.selecteda == 0){
			Weaps.Primary = Weaps.ListOfWeapons[Class1.selected];
			
		}
		if(Class1.selecteda == 1){
			Weaps.Primary = Weaps.ListOfWeaponsHolo[Class1.selected];
		}
		
		
		
		gameObject.name = PhotonNetwork.player.name;
		
		if(photonView.isMine){
			if(PhotonNetwork.player.customProperties["Team"].ToString() == "SAS")
				ArmMaterial.mainTexture = AlliesTexture;
			else if(PhotonNetwork.player.customProperties["Team"].ToString() == "GRU")
				ArmMaterial.mainTexture = AxisTexture;
			Cam.camera.enabled = true;
			//xp.enabled = true;
			Controller2.enabled = true;
			
			PublicPlayer.SetActiveRecursively(false);
			PlayerLook.enabled = true;
			CamLook.enabled = true;
			gun.SetActiveRecursively(true);
			//Cam.SetActiveRecursively(true);
			Cam.active = true;
			HealthCode.DoesAllow = true;
			hithud.enabled = true;
			//entre.enabled = true;
			GetComponent<CharacterController>().enabled = true;
			TPA.enabled = false;
		}
		else{
			//Weaps.Selected.active = true;
			//Weaps.Selected.GetComponent<Gun>().enabled = false;
			//Weaps.Selected.GetComponent<IsUsingGun>().enabled = false;
			hithud.enabled = false;
			//xp.enabled = false;
			Controller2.enabled = true;	
			Controller2.canControl = false;
			Cam.camera.enabled = false;
			PublicPlayer.SetActiveRecursively(true);
			PlayerLook.enabled = false;
			CamLook.enabled = false;
			gun.SetActiveRecursively(false);
			//Cam.SetActiveRecursively(false);
			Cam.active = false;
			HealthCode.DoesAllow = false;
			//entre.enabled = false;
			//GetComponent<CharacterController>().enabled = false;
			TPA.enabled = true;
			transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
			transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
		}
		
		if(HealthCode.Health <= 0)
			photonView.RPC("Det",PhotonTargets.All);
		
		if(Input.GetButtonDown("Crouch")){
			
			if(Crouch == false){
				photonView.RPC("Croouch",PhotonTargets.All);	
			}
			else{
				photonView.RPC("UnCrouch",PhotonTargets.All);	
			}
				
		}
			
		
			
	}
	
	void OnGUI(){
	//		if(HealthCode.hittimes >0)
			//HealthCode.hittimes -= Time.deltaTime;
			
			//GUI.color = new Color(1,1,1,HealthCode.hittimes);
			//if(photonView.isMine){	
			//	GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),HealthCode.HitTexture);
			//}
		if(photonView.isMine)
			GUILayout.Label(PhotonNetwork.player.customProperties["Team"].ToString());
	}
	
	
	[RPC]
	void Det(){
			Destroy(HealthCode);
			PublicPlayer.transform.parent = null;
			PublicPlayer.SetActiveRecursively(true);
			Rigidbody[] bodys = PublicPlayer.GetComponentsInChildren<Rigidbody>();
			foreach(Rigidbody body in bodys){
			body.isKinematic = false;
			}
			
			
		if(photonView.isMine){
			//Transform SpawnPos= HealthCode.Manager.PlayerSpawns[Random.Range(0,HealthCode.Manager.PlayerSpawns.Length)];
			//PhotonNetwork.Instantiate("SASBloke_AimRag",transform.position,transform.rotation,0);
			HealthCode.Manager.hasSpawn = false;
			HealthCode.Manager.ShowLeave = false;
			//PublicPlayer.AddComponent<PhotonView>();
			
			//Board.Deaths ++;
			PhotonNetwork.Destroy(this.gameObject);
			
			
		}
		
	}
	
	[RPC] 
	void Croouch(){
		PublicPlayer.transform.FindChild("SASBloke_AimRag").animation.CrossFade("Crouch",0.6f);	
		Crouch = true;
	}
	
	[RPC] 
	void UnCrouch(){
		PublicPlayer.transform.FindChild("SASBloke_AimRag").animation.CrossFade("Idle",0.6f);
		Crouch = false;
	}
	
	
	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if(stream.isWriting){
			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
		}
		else{
			correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();
			
		}
	}

}

Thanks
Tz
Bon-Fire

Comments

Sign In or Register to comment.