Forum rules - please read before posting.

Sprite rotation issue with Sprites Unity animation engine

edited September 23 in Engine development

Discovered this issue when working with an older game using AC 1.69.4, checked a newer project using AC 1.81.3 and noticed the same issue so I figured I would report it!

When using characters with the Sprites Unity animation engine, there is an issue where the sprite could end up getting stuck rotating. This will occur if the parent transform of the character ends up getting a non-zero rotation which ends up causing the sprite child to start rotating.

Here is the code causing it which resides in the UpdateSpriteChild method in Char.cs
else if (isUnity2D) { spriteChild.rotation = Quaternion.Euler(0f, 0f, spriteChild.localEulerAngles.z); }

So, the reason is that the global rotation for the sprite transform is being assigned to its local coordinate which means if anywhere in the hierarchy above the sprite a Z coordinate rotation has been defined it will cause the sprite to keep adding/subtracting that difference thus causing the sprite to keep rotating.

In my case, I was able to fix it by doing this
else if (isUnity2D) { spriteChild.rotation = Quaternion.Euler(0f, 0f, spriteChild.eulerAngles.z); }

In this case, it is always enforcing no rotational value on either the x or y coordinate within global space (which I believe is the purpose of this code)!

Now, I know generally you probably shouldn't have a rotational value on any of the transforms above it but in our case we were seeing this issue trigger in very rare circumstances with some players. I think the cause in our case was that the rigid body for the character was somehow getting a rotational velocity being applied or perhaps a rounding issue was occurring with a floating point resulting in a slight rotation to the character thus causing the issue. I unfortunately haven't determined WHY a rotation was occurring on the character to begin with as I could never proper duplicate it (I adjusted some code to freeze rotation on the RigidBody to help prevent this) but that is a separate problem.

Comments

  • Thanks for the details! I'll look into this and make the appropriate changes.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.