Hey guys!
I’m working on a project, where I move a fish on a beziere-curve path. The fish automatically rotates, depending on how I rotate the normals on the path (right now they simply look in the local y direction on a given point).
Because the swimming animation, looks like it’s clearly on some kind of rail, I implemented a blend tree, which lets the fish look in every direction (blends between up&down and left&right). So far so good.
The point I’m stuck right now is, that I don’t know how to communicate the x&y-rotation parameters via code from the gameObjects rotation to the blend tree. If I simply set the parameters to the rotation of my gameObject, there comes a point where the operator of the rotation magically inverts and therefore destroying the blending.
Is there some way to calculate the localRotation of my object, without Quaternion (at least I think they are part of the problem) interfering?

The blending works perfectly fine, it’s just the calculation to set the params, that bugs me… I just checked again, and in the inspector, the rotation keeps inverting when it hits -180 on an axis
Hey, I already managed to find a solution myself!
In case if anybody wonders, the reason you can’t just reference the rotation of your object, is because of the math behind quaternions, also eulerAngles don’t work, because eventually you’ll end up with a gimbal lock.
My solution was to just let another object with and offset run infront of my animated object. Then, I calculated two things:
First, whether the offsetPoint is higher or lower than the animated object on the y-Axis, to determine whether it was going up, or down and then just simply give the positive-/negative difference to the yRotation value.
For the xRotation, I offset the offsetPoint to the height of the animated object on the y-Axis, and then calculated the angle between the offsetPoint and the transform.right of the animated object. Then I simply checked, if the angle was higher, or lower a specefic number (in my case i subtracted 90 from my angle, to let it be 0, when the object moves straight forward)
float yRotation = offsetPoint.y - transform.position.y;
Vector3 angleCheckPoint = transform.right;
angleCheckPoint.y = transform.position.y; // make sure on same height, if not, the angle might change
Vector3 offsetAnglePoint = new Vector3(offsetPoint.x, transform.position.y, offsetPoint.z);
Vector3 checkDirection = offsetAnglePoint - transform.position;
float xRotation= Vector3.Angle(checkDirection, angleCheckPoint)-90f;
animator.SetFloat("xRotation", xRotation);
animator.SetFloat("yRotation", yRotation);
There are probably much better solutions for the problem, but this worked for me 