- Home /
Question by
Kattlelack · Jun 20, 2014 at 09:49 PM ·
transformpositionquaternionlerp
Lerp takes me to 0,0,0
Code:
transform.position = Vector3.MoveTowards (transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1);
thanks for the help!
Comment
You don't show us enough code here to be sure of the real problem. $$anonymous$$aking an educated guess, realPosition is likely a public variable that is Vector3.zero if you look at the value in the Inspector. Also typically this code has 'Time.deltaTime * speed' ins$$anonymous$$d of '0.1' as the last parameter.
heres the code:
using UnityEngine;
using System.Collections;
public class NetworkCharacter : Photon.$$anonymous$$onoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(photonView.is$$anonymous$$ine){
//Do nothing
}else{
transform.position = Vector3.$$anonymous$$oveTowards (transform.position, realPosition, 0.1f);
realPosition = transform.position;
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1);
realRotation = transform.rotation;
}
}
void OnPhotonSerializeView(PhotonStream stream, Photon$$anonymous$$essageInfo info){
if(stream.isWriting){
//Our player
stream.SendNext (transform.position);
stream.SendNext (transform.rotation);
}else{
//Someone else's player
transform.position = (Vector3)stream.ReceiveNext();
transform.rotation = (Quaternion)stream.ReceiveNext();
}
}
}
Best Answer
Answer by Kattlelack · Jun 20, 2014 at 10:09 PM
I fixed it! I wasn't updating the realPosition to the transform.position. Final Code:
using UnityEngine;
using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(photonView.isMine){
//Do nothing
}else{
transform.position = Vector3.Lerp (transform.position, realPosition, 0.1f);
realPosition = transform.position;
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
realRotation = transform.rotation;
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if(stream.isWriting){
//Our player
stream.SendNext (transform.position);
stream.SendNext (transform.rotation);
}else{
//Someone else's player
transform.position = (Vector3)stream.ReceiveNext();
transform.rotation = (Quaternion)stream.ReceiveNext();
}
}
}
Your answer
Follow this Question
Related Questions
Need to check transform.rotation 1 Answer
Add specific movement on double click 1 Answer
What does a Vector3 state? 1 Answer
Why does object lerp to above the object it is lerping to? 1 Answer
Turning character slowly with Slerp 1 Answer