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 OpsicInstantPesic · Apr 30, 2011 at 07:29 PM · rotationmultiplayeraxissynchronizationsingle

How to state synchronize the rotation of one axis?

Hi there!

In my multiplayer game I want to synchronize a Character's rotation(with state synchronization), but only one axis.

I would like the receiver just to receive the rotation of the one specific axis (looking left/ right), whereas the sender can also look up/down.

The problem is, that I don't really know how to do so.^^ As said, I've only managed to sync the whole rotation... I'm also very confused with all the different types of rotation (Quaternion, eulerAngles, vector3(?)). .O

Here is the code I got to synchronize (in C#):

using UnityEngine; using System.Collections;

public class Synchrnization : MonoBehaviour { void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) { if (networkView.isMine) { if (stream.isWriting) { Vector3 pos = transform.position; Quaternion rot = transform.rotation; stream.Serialize(ref pos); stream.Serialize(ref rot); } } else { if (!stream.isWriting) { Vector3 pos = Vector3.zero; Quaternion rot = Quaternion.identity; stream.Serialize(ref pos); stream.Serialize(ref rot); transform.position = pos; transform.rotation = rot; } } } }

/ I was wondering if any of you guys could help me out =). Any help would be appreciated. Thanks in advance /

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ashkan_gc · Apr 30, 2011 at 08:06 PM

Simply get the transform.eulerAngles.y (or x or z whatever you want) and put it in a float variable and then serialize it. when sending there is no problem. when receiving you should change the y rotation of the object to what you want and keep x and z with their previews values. the code would be something like this (the pother parts can be your own code).

float yRot;
void OnSerializeNetworkView (BitStream stream)
{
if (stream.isWriting)
{
float rot;
rot = yRot;
stream.Serialize (ref rot); //sending y axis rotation.
}
else
{
stream.Serialize (ref rot);
yRot = rot;
transform.rotation = Quaternion.Euler (transform.eulerAngles.x,yRot,transform.eulerAngles.z);
}
}

using quaternions is not easy so don't use them if you really don't know them the Quaternion.Euler method takes the rotation as x,y,z in eulerAngles (360 degree angles that we know well) and then returns a quaternion value that is the same rotation and you can set transform.rotation to it. i did not tested but transform.eulerAngles might be writable too.

Comment
Add comment · Show 1 · 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
avatar image OpsicInstantPesic · Apr 30, 2011 at 08:42 PM 0
Share

Thanks for your answer! I tried your solution, but ins$$anonymous$$d of rotating the character was just moving in some kind of circle (moving, not rotating =O). i also tried to directly change the transform.eulerAngles but it doesn't seem to be writable. .O The console also told me i had to instatiate and assign the rot variable in the else brackets. so it looks like this float rot = 0; stream.Serialize(ref rot); yRot = rot; hmm, i really don't know what to do =/

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

No one has followed this question yet.

Related Questions

A smooth single-axis rotaion (fps camera) 1 Answer

Network rotation is laggy and slow 2 Answers

90 Degree stopping rotation on y-axis issue 0 Answers

Transform.Translate but ignore rotation on one axis 0 Answers

Change rotation axis when importing from Maya 2 Answers


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