Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hans_vesthardt98 · May 26, 2014 at 11:23 AM · rotationpositionvector3quaternion

Vector3.Lerp moves other characters over network to (0, 0, 0)

I know this question has been asked a number of times, but the solution is not as easy as it seems. I am pretty sure I have done almost everything, but it STILL dosen't work. The solution in the other posts have been replace transform.position/rotation to realPosition/rotation. But that did not work for me. Any ideas?

Here is my code: using UnityEngine; using System.Collections;

 public class NetworkCharacter : Photon.MonoBehaviour {
 
     Vector3 realPosition = Vector3.zero;
     Quaternion realRotation = Quaternion.identity;
 
     Animator anim;
 
 
     // Use this for initialization
     void Start () {
         anim = GetComponent<Animator>();
         if(anim == null) {
             Debug.LogError ("ZOMG, you forgot to put an Animator component on this character prefab!");
         }
     }
     
     // Update is called once per frame
     void Update () {
         if( photonView.isMine ) {
             // Do nothing -- the character motor/input/etc... is moving us
         }
         else {
             transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
             transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
         }
     }
 
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
         if(stream.isWriting) {
             // This is OUR player. We need to send our actual position to the network.
 
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
             stream.SendNext(anim.GetFloat("Speed"));
             stream.SendNext(anim.GetBool("Jumping"));
         }
         else {
             // This is someone else's player. We need to receive their position (as of a few
             // millisecond ago, and update our version of that player.
 
             realPosition = (Vector3)stream.ReceiveNext();
             realRotation = (Quaternion)stream.ReceiveNext();
             anim.SetFloat("Speed", (float)stream.ReceiveNext());
             anim.SetBool("Jumping", (bool)stream.ReceiveNext());
         }
 
     }
 }
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hans_vesthardt98 · May 26, 2014 at 01:21 PM 0
Share

Bumping question

avatar image siaran · May 26, 2014 at 02:40 PM 0
Share

as far as I can tell your code should work... do you know if your objects are receiving correct realPosition and realRotation values?

avatar image hans_vesthardt98 · May 26, 2014 at 03:00 PM 0
Share

Yea, it should work. But no, actually, I am not even sure where it gets the realPosition and realRotation values from.. How can I define the realPos and realRot?

avatar image hans_vesthardt98 · May 26, 2014 at 06:22 PM 0
Share

Bumping question

avatar image siaran · May 26, 2014 at 06:57 PM 0
Share

is the photonView attached to your network object observing this script?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hans_vesthardt98 · May 26, 2014 at 09:43 PM

siaran gave me a lead to what was causing the issue, and then I fixed it. Since this is a common problem, here is a list of things that you can do in order to MAYBE fix it:

1). Make sure the first bit of the code on line 41/42 is realRotation and realPosition instead of transform.position and transform.rotation

2). Make sure that the photonView script is attached to your object, and that the object is Observing the script that I wrote in my question.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sync Rotations of objects with differing position and rotation 1 Answer

Connecting transform with Vector3 4 Answers

Rotating a direction Vector3 by Quaternion 2 Answers

Set rotation based on 1,1,1 style vector? How to convert vector3 to quaternion? 1 Answer

Help creating restraints for an objects movement according to it's parent 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges