I have a problem with Unity crashing out or, dying to 2 fps occasionally while running the code below (during a LateUpdate)…
I can’t see anything wrong with it, and it works most of the time.
Both vectors are normalized (after setting .Y to zero, so the bone adjustment is in horizontal plane).
aimPivot is a bone in a character’s spine.
(this is part of some gun aiming code)
It seems like aither the acos() or the rotate is causing strange things to happen to the aimpivot transform… Unity sometimes spits out a bunch of errors, such as…
Quaternion To Matrix conversion failed because input Quaternion is invalid { 1.#QNAN0, 1.#QNAN0, 1.#QNAN0, 1.#QNAN0}
and
!sh->m_AABB.IsValid()
UnityEngine.Transform:RotateAround(Vector3, Single)
… for the code below.
also, it only runs the code if the magnitude of both vectors is >.9 (not zero length vectors)
what can cause this please ?
ang = Mathf.Acos(Vector3.Dot(pivotWeaponDirection, pivotTargetDirection));
sgn = Mathf.Sign(Vector3.Cross(pivotWeaponDirection, pivotTargetDirection).y);
ang *= sgn;
aimPivot.Rotate(Vector3.up, ang * Mathf.Rad2Deg, Space.World);