Forum rules - please read before posting.

Quaternion error when using turn to face

Hello! When character's turn to face another character I receive the following error:

"Rotation quaternions must be unit length.
UnityEngine.Rigidbody:MoveRotation(Quaternion)
AC.Char:DoTurn(Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:1541)
AC.Char:_FixedUpdate() (at Assets/AdventureCreator/Scripts/Character/Char.cs:584)
AC.StateHandler:FixedUpdate() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:470)"

This happens once per prefab type, and then won't happen again if I unpause the scene. Does anyone have an idea what's going on/need more information?

Thanks!

Comments

  • Welcome to the community, @MegaTiny.

    The line endings don't match up with the current release - what versions of AC and Unity are you using?  Does this issue persist if you upgrade to the latest AC?

    We'll also need to see some character details, so please post screenshots showing your character's full Inspector.
  • Thanks for responding so quickly Chris. I updated AC and Unity and the error persists. Here's what the error message looks like now: 

    "Rotation quaternions must be unit length.
    UnityEngine.Rigidbody:MoveRotation(Quaternion)
    AC.Char:DoTurn(Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:1552)
    AC.Char:_FixedUpdate() (at Assets/AdventureCreator/Scripts/Character/Char.cs:586)
    AC.StateHandler:FixedUpdate() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:470)"

    Here are the screenshots requested:

    image

    image

    image

    Here is the Actionlist that is causing the error to occur. It is using Gameobject parameters to reference the characters. Though when called again in the scene the error will not occur again. I have tried removing the animate and follow before and after, the error persists if I do this.

    image

    Thanks for your help!
  • Which version of Unity are you now using, exactly?

    I can't recreate the issue, but it's likely to do with the "Character: Face object" Action.  What is the position of "Defender" in relation to "Attacker", and does removing it from the Action sequence remove the error message?

  • edited June 2018
    Hi Chris, apologies for not getting back to you. I've managed to fix this myself and here's what I believe the issue is:
    • I set up the navigation bake using Unity Navigation after a character was already in the scene
    • By removing and re-adding characters to a scene, the error is resolved permanently for that scene.
    • As long as the nav mesh has been baked at least once it can then be changed and rebaked without the issue re-occurring.
    While I fixed this just after you responded, I only just figured out how I fixed it and thought it would be nice to tell you the cause and solution.

    Anyway in case it helps you with any further updates (though this is a very minor bug caused by user error obviously. It's probably even in the flipping manual), I'm using Unity 2018.1.3f1.

    Thanks a lot for your quick help before, this is the best asset on the store by about a thousand miles.
  • You're welcome, thanks for the update.

    Were the characters being accounted for in the baked NavMesh?  That is, were "holes" in the NavMesh being created where they were standing?

    I don't quite follow what's going on, but if it works after multiple bakes, then it might be an issue with Unity itself - since AC only relies on the final bake and has no dealings with the actual baking process.
  • They weren't cutting holes into the nav-mesh no, it seemed to bake normally. Likely just me being a Unity derp, but as long as I've figured out how to stop it happening I'm happy.
  • edited June 2019

    I'm seeing this error frequently as well.

    Rotation quaternions must be unit length.
    UnityEngine.Rigidbody:MoveRotation(Quaternion)
    AC.Char:DoTurn(Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:1659)
    AC.Char:_FixedUpdate() (at Assets/AdventureCreator/Scripts/Character/Char.cs:610)
    AC.StateHandler:FixedUpdate() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:479)

    or

    Rotation quaternions must be unit length.
    UnityEngine.Rigidbody:MoveRotation(Quaternion)
    AC.Char:DoTurn(Boolean) (at Assets/AdventureCreator/Scripts/Character/Char.cs:1655)
    AC.Char:_FixedUpdate() (at Assets/AdventureCreator/Scripts/Character/Char.cs:610)
    AC.StateHandler:FixedUpdate() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:479)

    This is in Unity 2018.4.1f1 and AC 1.67.5.

    https://imgur.com/a/fpUxpBm

    I'd also note that re-baking the nav mesh and removing and re-adding the characters does not seem to fix it for me. It will occasionally play through successfully but it's pretty rare. When it fails the value of newRotation is always (0.0, 0.0, 0.0, 0.0).

  • edited June 2019

    Welcome to the community, @WillD.

    A few questions, to help figure out where this is coming from:

    1. Do your characters rely on Root Motion checked in the Animator, and if so - does the error persist if you uncheck this?
    2. At what point(s) do the errors show? When the ActionList you've posted is run? When/how is this run, if so?
    3. If you temporarily remove "0_ScientistMale", place the 3D Demo game's NPC, Brain (from AdventureCreator/Demo/NPCs), into the scene - and amend your Character: Face object Action to control him instead, does he also show the same error?
    4. Do the characters have any components that aren't in the screenshots? Does removing the "LOD Group" component have an effect on this issue?

    This'll be hard to pin down without seeing the issue for myself, but try opening up Char.cs, and inserting the following just inside the _Awake function (around line 396):

    newRotation = TransformRotation;
    lookDirection = TransformForward;
    

    Please try both of these additions separately, and together (i.e. all 3 combinations) and let me know which work (if any). If all else fails, you can PM me your scene + character prefabs as a .unitypackage file - but let's see the results of this first.

  • edited June 2019

    Thanks Chris!

    1. They do and unchecking it has no effect.
    2. The error shows up when it executes Character: Face Object and it's run as an opening cutscene sequence when the scene loads.
    3. I did not see the error using the Brain character.
    4. They have a number of other components, but all standard stuff. Animator, Rigidbody, Audio Source, Paths. Most/all of that was added when I went through the AC NPC wizard. Removing the LOD grouping does not impact the issue.

    Adding the newRotation=TransformRotation in the _Awake function solves the issue. It also works with newRotation=TransformRotation and lookDirection=TransformForward, but not with just lookDirection=TransformFoward. Not sure what's up with my character models that causes the issue. I made them out of Reallusion's character creator. In any case, thanks for coming up with a fix for it so quickly!

  • Thanks for the feedback.

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.