playMaker

Author Topic: Photon - Received rotation is jerky (not smooth)[SOLVED]  (Read 11935 times)

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • AL Games
Photon - Received rotation is jerky (not smooth)[SOLVED]
« on: October 18, 2013, 05:50:29 PM »
Hello,

I downloaded this: PlayMaker Photon Demo
http://www.hutonggames.com/samples.php

Received position on network is very smooth with this custom action: Vector3 Lerp 2
http://hutonggames.com/playmakerforum/index.php?topic=1126.msg4726#msg4726


But rotation have very bad looking and jerky... it's not smooth like a position:



How i can have beautiful and smooth rotation too?

I find these custom actions:
https://hutonggames.fogbugz.com/default.asp?W967
They have: Quaternion and Lerp, but do i need another custom action like a Vector3 Lerp 2, because there is added deltatime too?

Please, can anyone give me example with picture or package for "receiving smooth rotation on network with photon"?

Thanks!
« Last Edit: January 03, 2014, 04:24:16 AM by jeanfabre »

Zeathlar

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Photon - Received rotation is jerky (not smooth)
« Reply #1 on: October 18, 2013, 07:09:40 PM »
Jelloh Ermak. One thing to do is just to do the same thing you did with with the position here is what I did.

It does have a small problem of doing a 360 sometimes, but it works

Hope this helps

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • AL Games
Re: Photon - Received rotation is jerky (not smooth)
« Reply #2 on: October 19, 2013, 12:54:26 PM »
Hi,

I tryed the same thing for rotation with Vector3 Lerp 2 - yes its smooth,
but 360 degree problem is big, not small.

(watch on HD 720p)

I think the key for my problem is here (Quaternion Lerp):
https://hutonggames.fogbugz.com/default.asp?W967
but i dont know how to use these actions for "smooth network rotation"...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon - Received rotation is jerky (not smooth)
« Reply #3 on: October 21, 2013, 02:40:08 AM »
Hi,

 Yes, you will need to mess with quaternions I am afraid.

 You may have a problem when you save the rotation not when you smooth it out ( you need to check that the rotation you send it valid).

Typically, you first need to solve this without Photon being involved. Create a new scene, without any photon stuff, rotate one object, store the rotation into a global rotation, and have another object smooth follow that rotation, once you have that sorted, you can apply the same logic within your photon enabled character.

 Doing it this way will save you a lifetime!

bye,

 Jean

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • AL Games
Re: Photon - Received rotation is jerky (not smooth)
« Reply #4 on: November 11, 2013, 01:11:08 PM »
Hi again, thanks for advices.

I found this: Photon BootCamp Demo Documentation
http://doc.exitgames.com/photon-cloud/DemoBootcamp/

Quote
Setting the transform position and rotation directly would cause the remote players to jump from position to position. To make movement appear smooth we update the position with Vector3.Lerp() and the rotation with Quaternion.Slerp() in usePhoton.cs in every frame.

Code: [Select]
if (!player.playerRemote.Dead)
            {
                // set this Transform position
                t.transform.position =
                   Vector3.Lerp(t.transform.position, player.playerRemote.pos, Time.deltaTime * 7.0f);
                 
                // set this Transform rotation
                t.transform.localRotation =
                    Quaternion.Slerp(t.transform.localRotation, player.playerRemote.rot, Time.deltaTime * 7.0f);
            }

Of course i try it with "Quaternion lerp" and "Slerp". Result is not perfect, but is better than before. I think "Slerp" working better than "lerp" for network rotation.

(watch on HD 720p)

In BootCamp Demo is used "deltaTime" too for rotation:
Quaternion.Slerp(t.transform.localRotation, player.playerRemote.rot, Time.deltaTime * 7.0f);

jeanfabre, please, can you add "deltaTime" option in new custom actions for Quaternion.Slerp and Quaternion.lerp, if you have free time in the future?
Like a Vector3 Lerp 2, but this time:
Quaternion.Slerp 2
Quaternion.lerp 2
https://hutonggames.fogbugz.com/default.asp?W1093
https://hutonggames.fogbugz.com/default.asp?W1092
Maybe with deltaTime rotation result will be perfect and very smooth on the photon network:



Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon - Received rotation is jerky (not smooth)
« Reply #5 on: November 12, 2013, 01:07:36 AM »
Hi,

 Currently to do that manually, simple multiply your lerp value with the delta time using the action "GetTimeInfo", store thet deltatime in a variable and multiply this deltatime with your lerp value.

 I have added it to the trello todo list so the next iteration of the quaternion package will have them option built in.

https://trello.com/c/Sd1J0JQV/23-quaternion-package-update

Simply pm me with your email so that I can invite you to the board to vote up this task ( and/or others) and get it done next.


bye

Jean

flu2120

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Photon - Received rotation is jerky (not smooth)
« Reply #6 on: December 01, 2013, 08:10:03 PM »
Has there been any progress on smooth rotation eg tutorial to get it to work? Currently struggling at getting the most simple scene object to rotate smoothly in just one axis.

Regards,

Simon

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon - Received rotation is jerky (not smooth)
« Reply #7 on: December 02, 2013, 01:24:58 AM »
Hi,

 Not yet unfortunatly, I am still working on porting Photon to work properly on All platforms, then I can tackle more tutorials.

 Bye,

 Jean

flu2120

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Photon - Received rotation is jerky (not smooth)
« Reply #8 on: December 02, 2013, 04:30:22 PM »
Hi Jean,

No problem, I like the rest of the people looking for help over here can obviously see that you're very busy.

I tried your non photon idea, by getting one box to rotate through the press of a button and have another box utilising its variables to rotate and am having the same non smooth rotation issues. So it is indeed not photon.

However, as far as I can see, both are using the same numbers for the rotation degrees, so I don't understand why one would move smooth and the other would move rugged.

I did find out though, that if I have them both rotating utilising real world time (per second) that the main box moves at a constant pace. Whereas, the box that gets all its rotation information from its parent, starts very slow and actually accelerates. Very interesting, but I have no idea as to why nor how to fix it.

Regards,

Simon

flu2120

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Photon - Received rotation is jerky (not smooth)
« Reply #9 on: December 02, 2013, 06:09:27 PM »
Just to add to my previous post, here is my attempt at using quaternion values to mirror the rotation of one cube to another.

Below: The parent cube. This cube is designed to rotate along the y axis when the a button is pressed.


Below: This is the dummy cube. It obtains its rotation values off the parent. I tried using both Euler angles as well as the quaternions, however it seemed to do the same thing.



Im sure my quaternion setup is wrong, as I have no idea what I am doing and simply connecting the pieces of the puzzle I think should fit. However, even using euler angles, the rotation that I am getting on the child (dummy object) is completely different. Looks like its spinning 1000 rotations before the parent object even reaches one.

Any help would be vastly appreciated.

Regards,

Simon

flu2120

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Photon - Received rotation is jerky (not smooth)
« Reply #10 on: December 02, 2013, 10:50:43 PM »
Hmmmm, I have actually got the two boxes sync using an itween Rotate update action on the dummy box. Could this work in a photon setup in a similar fashion?

Regards,

Simon

P.S sorry for replying re-replying to my own posts :p

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon - Received rotation is jerky (not smooth)
« Reply #11 on: December 04, 2013, 04:40:07 AM »
Hi,

 not really, iTween shoudl be avoided for such case ( any tweening engines), you only need to lerp the quaternion. In your case I think you should directly inject the rotation quaternion instead of going through euler and roation, use the "set rotation" and pass the lerped quaternion, that's the best way.

bye,

 Jean

flu2120

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Photon - Received rotation is jerky (not smooth)
« Reply #12 on: January 02, 2014, 04:59:28 PM »
Hi,

Thanks for the help Jean. After walking away from this problem and coming back to it, I started to understand your solution quite quickly.

For those that come to this thread and are having the same problems I was, this is the setup to get one box to rotate in sync with the other (Smoothly).

Parent FSM


Dummy FSM



The problem I had with understanding this was, what two values should I be lerping together?? Then it hit me, I needed to be storing the dummy boxes current rotation and lerping it with the parents! Seems so simple now. Hopefully I can implement this logic into my photon setup now.

Regards,

Simon

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Photon - Received rotation is jerky (not smooth)
« Reply #13 on: January 03, 2014, 04:23:58 AM »
Hi Simon,

 Thanks for sharing your findings and process, it's very important, and I am glad for you.

Indeed, never give up! Networking has lots of concepts difficult to understand, and difficult to explain...  ::) so keep at it, leave it for a while, then try again, everytime it will make more and more sense.

Have a good day,

 Jean