playMaker

Author Topic: Smooth rotation over network [solved with Quaternion lerp]  (Read 7309 times)

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Smooth rotation over network [solved with Quaternion lerp]
« on: December 06, 2013, 04:47:59 PM »
Hello

I use Vector3Lerp action in my multiplayer game for smooth position and rotation.

The pose smooth is very good, but the rotation smooth have a problem, what I think we can solve with a little help.

I synch a ship, and this ship is moving and turning slowly, but when the ship rotate is going over the 360° the next point is 1° ...

The problem is, that the Vector3Lerp not turning over 360°, it turn back to 1° and after turn more...

So my ship when turning over a full curve, look like a stupid... Because turning back 359° in 1 sec and after turn more..


Can we change the vector3Lerp code, that dont turn back, turn for the closest direction? turn over 360° to 1° and dont turn back

Or how can I solve the rotation smooth without Vector3Lerp?

Pls help, Thank you.
« Last Edit: December 12, 2013, 05:15:39 PM by Bqlqzs »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Vector3Lerp code change help
« Reply #1 on: December 09, 2013, 02:18:55 PM »
Hi,

 rotation lerping should be done using a quaternion represenation of the rotation, not a vector3, else you will always face gimbal lock issues ( what you are experiencing currently).

There is a set of custom actions for this:

http://hutonggames.com/playmakerforum/index.php?topic=1934.0

bye,

 Jean
 

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Re: Vector3Lerp code change help
« Reply #2 on: December 10, 2013, 04:12:02 AM »
Hi,

 rotation lerping should be done using a quaternion represenation of the rotation, not a vector3, else you will always face gimbal lock issues ( what you are experiencing currently).

There is a set of custom actions for this:

http://hutonggames.com/playmakerforum/index.php?topic=1934.0

bye,

 Jean

Thank you, is this action what I need?
Quaternion Lerp
https://hutonggames.fogbugz.com/default.asp?W1092

I not understand what is and how Quaternion,
It working as the vector3?
So I get the objec Quaternion, after Quaternion Lerp, and set? Thats all?
« Last Edit: December 10, 2013, 04:20:04 AM by Bqlqzs »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Vector3Lerp code change help
« Reply #3 on: December 10, 2013, 08:12:26 AM »
A while back I was looking for a way to make a seamless rotation value that would roll from 360-0 without doing that bounce back problem. I guess that is known as gimbal lock? Anyway I was overwhelmed by Quaternions so I just subtracted the rotation by 360 when it went beyond 180 degrees and that gave me a stable rotational value to work with.

Quaternions are better for sure, but I couldn't figure out how to apply them and this was my hack around it. If you're struggling with Quats then maybe this will work for you.

See the attached scene for an example.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Re: Vector3Lerp code change help
« Reply #4 on: December 10, 2013, 05:11:54 PM »
A while back I was looking for a way to make a seamless rotation value that would roll from 360-0 without doing that bounce back problem. I guess that is known as gimbal lock? Anyway I was overwhelmed by Quaternions so I just subtracted the rotation by 360 when it went beyond 180 degrees and that gave me a stable rotational value to work with.

Quaternions are better for sure, but I couldn't figure out how to apply them and this was my hack around it. If you're struggling with Quats then maybe this will work for you.

See the attached scene for an example.

Thank you, but this is more difficult... why can not we do it in a revised simple Lerpt action?

Really havent a simple solution for this?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Vector3Lerp code change help
« Reply #5 on: December 10, 2013, 05:37:33 PM »
Quaternions are basically there to bypass this inherit problem from what I understand.

http://forum.unity3d.com/threads/73406-6DOF-banking-and-pesky-gimbal-lock
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Re: Vector3Lerp code change help
« Reply #6 on: December 10, 2013, 05:47:53 PM »
It isnt work for me... I use this for remote, and in mine: get rotation (Quaternion)and set this value every frame in to network synch
« Last Edit: December 10, 2013, 06:05:41 PM by Bqlqzs »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Vector3Lerp code change help
« Reply #7 on: December 11, 2013, 07:31:36 AM »
How is this behaving with this?

Get Rotation is wrt World, and Set Rotation is wrt Self. That could be an issue.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Vector3Lerp code change help
« Reply #8 on: December 11, 2013, 02:27:13 PM »
Hi,

 It's indeed always tricky to work with rotations, at some point unfortunatly, this kind of complexity is unavoidable.

one things: avoid using euler at all, this is likely the cause of your problem, don't extract the euler angles from a quaternion operation, else it defeats the whole point, inject the quaternion directly into the rotation using "set rotation" action.

bye,

 Jean

Bqlqzs

  • Junior Playmaker
  • **
  • Posts: 52
Re: Vector3Lerp code change help
« Reply #9 on: December 12, 2013, 04:18:34 PM »
I found the solution!

So if anybody want smooth rotation synch over the network:

owned object:
- get rotation (Quaternion) and send this over the network

in the remoted object:
- get the synched Quaternion, Quaternion lerp, and set rotation (Quaternion)

Thats all, but when I was looking for solution I not found this anywhere...
I think it need to put in the playmaker network demo.. because in the demo was vector3 lerp for rotation...

« Last Edit: December 12, 2013, 05:14:06 PM by Bqlqzs »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Smooth rotation over network [solved with Quaternion lerp]
« Reply #10 on: December 14, 2013, 12:53:31 PM »
Hi,

 Good. I am glad you found your way in this!

bye,

 Jean